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

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

From
Mário Guimarães <mario.luis.guimaraes@gmail.com>
Date
Nov 4, 2020, 02:11 UTC
Message-ID
<CAF7CYk6SVx396=fLZ2yMVTaS2XK58M_=kT7J+th_T8VqM+HmaQ@mail.gmail.com>
In-Reply-To
<xmqqk0v1q60l.fsf@gitster.c.googlers.com>
Hello
Junio C Hamano <gitster@pobox.com> escreveu no dia quarta, 4/11/2020 à(s) 01:12:
Show 61 quoted lines
>
> 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.
>
> > 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`.

What about this? It makes clear that the prefix is still one that can be used to identify the object in the repository.

diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index ee52b65e46..c15b4adb28 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -446,8 +446,9 @@ 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.
-       In diff-patch output format, `--full-index` takes higher
+       lines, show only the minimal prefix that identifies
+       the object using 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`.
        Non default number of digits can be specified with `--abbrev=<n>`.
Previous: Derrick Stolee
Message 7 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.