Git - finding the SHA1 of an individual file in the index

后端 未结 3 842
猫巷女王i
猫巷女王i 2020-11-30 23:29

I\'ve added a file to the \'index\' with:

git add myfile.java

How do I find out the SHA1 of this file?

3条回答
  •  -上瘾入骨i
    2020-12-01 00:11

    You want the -s option to git ls-files. This gives you the mode and sha1 hash of the file in the index.

    git ls-files -s myfile.java
    

    Note that you do not want git hash-object as this gives you the sha1 id of the file in the working tree as it currently is, not of the file that you've added to the index. These will be different once you make changes to the working tree copy after the git add.

提交回复
热议问题