如何在git中消除模糊的缩写sha1 [英] How to disambiguate an ambiguous abbreviated sha1 in git
问题描述
假设有人在缩写明确的时候写下了一个缩写的提交ID 8b82547e33
。但从那时起,其他对象已经创建了相同的前缀,所以现在git告诉你(出于某种原因两次):
$ git show 8b82547e33
错误:短的SHA1 8b82547e33不明确。
错误:短SHA1 8b82547e33不明确。
致命:不明确的参数'8b82547e33':未知的版本或路径不在工作树中。
使用' - '分隔修订版本的路径,如下所示:
'git< command> [< revision> ...] - [< file>]'
现在,作为一个人,我可能会告诉我是哪个对象,如果git会让我看到模糊的对象。
$ git objects-starting-with 8b82547e33
8b82547e33e:commit:l2tp :sendmsg成功时恢复套接字refcount
8b82547e338:tree [2文件,26子树]
(注意:上面的例子使用了一个相对较新的 http:// git .kernel.org / cgit / linux / kernel / git / stable / linux-stable.git 。)
你可以使用 git rev-parse
,假设你至少有一个4位数字的前缀。
git rev-parse --disambiguate = 8b82547e33
I was intrigued by Josh Stone's analysis of sha1 abbreviation collisions.
Let's say somebody wrote down an abbreviated commit id, 8b82547e33
, at a time when it was unambiguous. But since then other objects have been created with that same prefix, so that now git tells you (twice, for some reason):
$ 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>...]'
Now, as a human, I could probably tell which object I meant if git would just show me the ambiguous objects. How can I achieve something like the following?
$ git objects-starting-with 8b82547e33
8b82547e33e: commit: l2tp: Restore socket refcount when sendmsg succeeds
8b82547e338: tree [2 files, 26 subtrees]
(Note: the above examples are using a relatively current clone of http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git.)
You can use git rev-parse
, assuming you have at least a 4-digit prefix of the full hash.
git rev-parse --disambiguate=8b82547e33
这篇关于如何在git中消除模糊的缩写sha1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!