git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: rev-list and "ambiguous" IDs

From
Jeff King <peff@peff.net>
Date
Nov 15, 2019, 03:49 UTC
Message-ID
<20191115034941.GB20863@sigill.intra.peff.net>
In-Reply-To
<ab4dcc9c-4416-aef8-c8c4-38bb5ec97990@virtuell-zuhause.de>
On Fri, Nov 15, 2019 at 01:12:47AM +0100, Thomas Braun wrote:
Show 7 quoted lines
> > That would probably help in a lot of cases, but the argument
> > against it is that when it goes wrong, it may be quite confusing (so
> > we're better off with the current message, which punts back to the
> > user).
> 
> Just out of curiosity: Is there a use case for inspecting non-commit
> objects with git log?
Not that I can think of. You can't even say "--objects" there.

And indeed, "git log" already prefers commits for disambiguation, since d5f6b1d756 (revision.c: the "log" family, except for "show", takes committish, 2012-07-02).

But...
Show 21 quoted lines
> If I do (in the git repo)
> 
> $ git log 1231
> 
> I get
> 
> error: short SHA1 1231 is ambiguous
> hint: The candidates are:
> hint:   123139fc89 tree
> hint:   12316a1673 tree
> hint:   123144fe8a blob
> fatal: ambiguous argument '1231': unknown revision or path not in the
> working tree.
> Use '--' to separate paths from revisions, like this:
> 'git <command> [<revision>...] -- [<file>...]'
> 
> with
> $ git --version
> git version 2.24.0.windows.2
> 
> and all of these candidates are no commits.

...remember that the disambiguation code is just about preferring one object to the other. If the rule in effect doesn't have a preference, it's still ambiguous. On my system, "1231" actually _does_ have a commit:

  $ git show 1231
  error: short SHA1 1231 is ambiguous
  hint: The candidates are:
  hint:   12319e3bf2 commit 2017-03-25 - Merge 'git-gui-add-2nd-line' into HEAD
  hint:   123139fc89 tree
  hint:   12315b58b8 tree
  hint:   12316a1673 tree
  hint:   12317ab2d9 tree
  hint:   123193f802 tree
  hint:   123144fe8a blob
  fatal: ambiguous argument '1231': unknown revision or path not in the working tree.
  Use '--' to separate paths from revisions, like this:
  'git <command> [<revision>...] -- [<file>...]'

That's ambiguous because git-show can handle trees and blobs, too. But if I feed that sha1 to git-log:

  $ git log --oneline -1 1231
  12319e3bf2 Merge 'git-gui-add-2nd-line' into HEAD

it's perfectly fine, because git-log knows to disambiguate the commit. But if I choose another prefix that has no commits at all, it's ambiguous under either, because the "committish" rule has no way to decide:

  $ git show abcd2
  error: short SHA1 abcd2 is ambiguous
  hint: The candidates are:
  hint:   abcd22f55e tree
  hint:   abcd238df0 tree
  hint:   abcd2b1cc8 blob
  
  $ git log abcd2
  error: short SHA1 abcd2 is ambiguous
  hint: The candidates are:
  hint:   abcd22f55e tree
  hint:   abcd238df0 tree
  hint:   abcd2b1cc8 blob
-Peff
Previous: Thomas BraunNext: Thomas Braun
Message 4 of 13 in “rev-list and "ambiguous" IDs”
  1. Bryan TurnerNov 14, 2019
  2. Jeff KingNov 14, 2019
  3. Thomas BraunNov 15, 2019
  4. Jeff KingNov 15, 2019
  5. Thomas BraunNov 15, 2019
  6. Junio C HamanoNov 16, 2019
  7. Jeff KingNov 18, 2019
  8. Junio C HamanoNov 19, 2019
  9. Junio C HamanoNov 15, 2019
  10. Jeff KingNov 15, 2019
  11. Junio C HamanoNov 15, 2019
  12. Bryan TurnerNov 15, 2019
  13. Jeff KingNov 15, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.