如何从diff输出中获取提交的SHA?

时间:2016-04-25 08:07:20

标签: git git-diff git-checkout git-show

如何从diff输出中获取提交的SHA?

例如,我喜欢区分二进制文件,git show COMMIT的输出是:

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

git show 9993010显示终端上的文件,但是如果我将其重定向到 一个文件并用MS Excel打开,它包含垃圾。

git checkout 9993010fatal: reference is not a tree: 9993010

如何查看ab的版本?

1 个答案:

答案 0 :(得分: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?