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

Re: Bug with --abbrev option in git log?

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 4, 2020, 01:12 UTC
Message-ID
<xmqqk0v1q60l.fsf@gitster.c.googlers.com>
In-Reply-To
<CAF7CYk51BC0KcsBb0KjKWAj17AMU2c9Y6Y81ddwX6oOAFYhT8w@mail.gmail.com>
Mário Guimarães  <mario.luis.guimaraes@gmail.com> writes:
> In the Git repository run this command:
>
> git log --raw -r -c --abbrev=6 --pretty=oneline -n1
> a7144d4bc5ab58f306a1e5c73b27196fb999a63d

This is not one of my object, so above won't be usable as reproduction recipe. But that is OK.

Show 11 quoted lines
> What did you expect to happen? (Expected behavior)
>
> I was expecting to get this line in the output
>
> ::100644 100644 100644 639a41 111378 05ba1d MM Documentation/git-rebase.txt
>
> What happened instead? (Actual behavior)
>
> I got the following line instead
>
> ::100644 100644 100644 639a41 111378 05ba1d3 MM Documentation/git-rebase.txt

The above command tells us that you locally have an object whose name begins with 05ba1d3, which I do not have. But my history shared with the entire world has an object whose name begins with 05ba1d7, and I am reasonably sure that your repository has it, since it is a part of 17f26a9e (git-am: fix shell quoting, 2009-01-14).

So in my repository, 05ba1d is enough to uniquely identify 05ba1d7, but in your repository 05ba1d is not enough to uniquely identify 05ba1d3, because 05ba1d7 also exists in your repository. And when the object cannot be uniquely specified with the given abbreviation width, Git makes sure its output is usable to uniquely identify the object it wants to name.

In short, I think what you observed is totally expected.
The documentation has some room for improvement, I also think.
How about saying something like this?
 Documentation/diff-options.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git i/Documentation/diff-options.txt w/Documentation/diff-options.txt
index ee52b65e46..114e440c5b 100644
--- i/Documentation/diff-options.txt
+++ w/Documentation/diff-options.txt
@@ -446,7 +446,8 @@ endif::git-format-patch[]
 --abbrev[=<n>]::
 	Instead of showing the full 40-byte hexadecimal object
 	name in diff-raw format output and diff-tree header
-	lines, show only a partial prefix.
+	lines, show only a partial prefix that uses at least '<n>'
+	hexdigits.
 	In diff-patch output format, `--full-index` takes higher
 	precedence, i.e. if `--full-index` is specified, full blob
 	names will be shown regardless of `--abbrev`.
Previous: Mário GuimarãesNext: Junio C Hamano
Message 2 of 7 in “Bug with --abbrev option in git log?”
  1. Mário GuimarãesNov 4, 2020
  2. Junio C HamanoNov 4, 2020
  3. doc: clarify that most --abbrev[=<n>] are about minimum lengthJunio C Hamano, Nov 4, 2020
  4. Derrick StoleeNov 4, 2020
  5. doc: clarify that --abbrev=<n> is about the minimum lengthJunio C Hamano, Nov 4, 2020
  6. Derrick StoleeNov 7, 2020
  7. Mário GuimarãesNov 4, 2020

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.