我对 Josh Stone's analysis of sha1 abbreviation collisions 很感兴趣.
假设有人写下了一个缩写的提交 ID,8b82547e33
,当时它是明确的。但是从那以后,其他对象已经用相同的前缀创建,所以现在 git 告诉你(出于某种原因两次):
$ git show 8b82547e33
error: short SHA1 8b82547e33 is ambiguous.
error: short SHA1 8b82547e33 is ambiguous.
fatal: ambiguous argument '8b82547e33': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
现在,作为一个人,如果 git 只向我显示模棱两可的对象,我可能会说出我指的是哪个对象。我怎样才能实现如下目标?
$ git objects-starting-with 8b82547e33
8b82547e33e: commit: l2tp: Restore socket refcount when sendmsg succeeds
8b82547e338: tree [2 files, 26 subtrees]
(注意:以上示例使用的是相对较新的 http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git 克隆。)
最佳答案
你可以使用 git rev-parse
,假设你至少有一个完整哈希的 4 位前缀。
git rev-parse --disambiguate=8b82547e33
关于git - 如何在 git 中消除歧义的缩写 sha1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27428441/