索引文件是什么样的有什么关系?重要的是它列出的文件的版本。您可以通过ls-files
.
例子:
$ git init
$ echo "howdy" > howdy.txt
$ git add .
$ git commit -m "root"
$ echo "bonjour" >> howdy.txt
$ echo "byebye" > byebye.txt
$ git add .
$ git commit -m "first"
$ git ls-files --stage
100644 3abe061d90cd975b4bef1fa702caec7c0f320b29 0 byebye.txt
100644 e1f6537eb149ccead2e53cbf2da40291c07d904a 0 howdy.txt
好的,这些是索引的“内容”。现在让我们进行更改和新的提交:
$ echo "extra line" >> howdy.txt
$ git add .
$ git commit -m "second"
$ git ls-files --stage
100644 3abe061d90cd975b4bef1fa702caec7c0f320b29 0 byebye.txt
100644 1ad49f2d780a4b46f68dd9bb1571c65ffc1dc660 0 howdy.txt
现在让我们重置:
$ git reset --hard HEAD^
$ git ls-files --stage
100644 3abe061d90cd975b4bef1fa702caec7c0f320b29 0 byebye.txt
100644 e1f6537eb149ccead2e53cbf2da40291c07d904a 0 howdy.txt
如您所见,索引与它原来的索引“相同”,这是唯一重要的意义。