Matt McHenry Matt McHenry - 1 year ago 93
Git Question

How to disambiguate an ambiguous abbreviated sha1 in git

I was intrigued by Josh Stone's analysis of sha1 abbreviation collisions.

Let's say somebody wrote down an abbreviated commit id,

, 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

Answer Source

You can use git rev-parse, assuming you have at least a 4-digit prefix of the full hash.

git rev-parse --disambiguate=8b82547e33
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download