0

How can I get the SHA of the commit from diff output?

For example I like to diff a binary file, the output of git show COMMIT is:

diff --git a/0_prospektusok/FAR_feltetdiszek/feltetdisz_prospektus.xls b/0_prosp
index 9993010..707c169 100644
Binary files a/0_prospektusok/FAR_feltetdiszek/feltetdisz_prospektus.xls and b/0

The git show 9993010 shows the file on terminal, but if I redirecting it to a file and opening with MS Excel, it contains junk.

The git checkout 9993010 says fatal: reference is not a tree: 9993010.

How can I checkout the versions of a and b?

bimlas
  • 2,359
  • 1
  • 21
  • 29
  • Possible duplicate of http://stackoverflow.com/questions/19224476/how-does-index-f2e4113-d4b9bfc-100644-in-git-diff-correspond-to-sha1-id-in-gi (I don't want to close this as a duplicate yet though) – torek Apr 25 '16 at 08:54

1 Answers1

1

If you want to checkout the whole repo as it was before COMMIT use git checkout COMMIT~.
If you want to keep your working copy and all but only update the file to the state that it had before COMMIT, use git checkout COMMIT~ -- 0_prospektusok/FAR_feltetdiszek/feltetdisz_prospektus.xls.
For explanation why git checkout 9993010 didn't work, read the answer to How does "index f2e4113..d4b9bfc 100644" in git diff correspond to SHA1 ID in gitk?

Community
  • 1
  • 1
Vampire
  • 35,631
  • 4
  • 76
  • 102
  • And how can I find out the SHA of the commit which introduces `9993010`? – bimlas Apr 25 '16 at 10:14
  • This is not uniquely identifyable, as this is just the blob with the file contents which could appear in any amount of commits. You can use one of the scripts from the answer to http://stackoverflow.com/questions/223678/which-commit-has-this-blob to get all commits that contain a blob. But as you did `git diff COMMIT`, what you are after is `COMMIT~`. – Vampire Apr 25 '16 at 10:23