咱们知道git commit提交命令是基于暂存区的,若是修改了工做空间的内容,必须使用git add /git rm等把修改添加到暂存区,不然没法提交。java
在.git目录下有个index文件,这个就是暂存器文件,当咱们使用修改暂存区命令的时候,这个文件就会更新。node
暂存区中存储的是git blob对象的引用,以及blob对象的一些路径信息。咱们能够使用 git ls-files --stagegit
$ git ls-files --stage 100644 72943a16fb2c8f38f9dde202b7a70ccc19c52f34 0 fas.txt 100644 f910c723c9bbc92b2d61c094859e68bbf7215ab2 0 hello.txt 100644 b08a2810d8a4542f350f650435f506c6c81ca9b2 0 src/hello.txt
当咱们使用notepad++使用十六进制格式打开该文件,内容以下:
其对应的格式为:bash
| 0 | 4 | 8 | C | |-----------------------|----------------------|------------------------|----------------------| 0 | DIRC | Version | File count | ctime ... | 0 | ... | mtime | device | 2 | inode | mode | UID | GID | 2 | File size | Entry SHA-1 ... | 4 | ... | Flags | Index SHA-1 ... | 4 | ... |
后面的内容是每个文件的信息列表。若是有多个文件则依次按照下面的顺序读取ide
String s = "临时目录/hello.txt"; byte[] bytes = s.getBytes("utf-8"); for (byte b : bytes) { System.out.print(Integer.toHexString(b & 0xFF) + " "); } 输出:e4 b8 b4 e6 97 b6 e7 9b ae e5 bd 95 2f 68 65 6c 6c 6f 2e 74 78 74
最后的二十位为以上内容的校验和。
参考:https://stackoverflow.com/questions/4084921/what-does-the-git-index-contain-exactly编码
分段提交,可能不想把整个工做空间的修改内容提交,加入暂存区就能够分段提交
https://www.zhihu.com/question/19946553code