Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get SHA of file for specific Git commit?

Tags:

git

commit

sha

Is there a way to get SHA of file for specific Git commit?

It's possible with 2 commands:

  1. retrieving file git show COMMIT_VERSION:myfile.txt > ~/tmp/myfile.txt
  2. calculating SHA git hash-object ./tmp/myfile.txt

But, maybe there's specific command in Git that does exactly that?

like image 296
Alex Craft Avatar asked Aug 18 '12 08:08

Alex Craft


People also ask

What is the SHA of a git commit?

"SHA" stands for Simple Hashing Algorithm. The checksum is the result of combining all the changes in the commit and feeding them to an algorithm that generates these 40-character strings. A checksum uniquely identifies a commit.


1 Answers

git ls-tree COMMIT_VERSION myfile.txt appears to contain the same result in its third field.

like image 189
Alan Curry Avatar answered Oct 28 '22 18:10

Alan Curry