tags:

views:

337

answers:

2

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

git add myfile.java

How do I find out the SHA1 of this file?

+2  A: 
$ git hash-object myfile.java
802992c4220de19a90767f3000a79a31b98d0df7
cnu
Thanks a lot! - that did the trick.
git-noob
Ah, you could as well thank me by accepting the answer :-)
cnu
Here's why this answer got rated worse than the one by Charles: this actually gives you the SHA1 of the version of the file that's in the working tree, not of the indexed/staged version. It also has the disadvantage that it needs to recalculate the SHA1 even if it's already stored in the index.
Jan Krüger
+7  A: 

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.

Charles Bailey