咱們知道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