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

Re: --abbrev-commit gives longer hash than necessary

From
Jeff King <peff@peff.net>
Date
Jul 1, 2016, 06:22 UTC
Message-ID
<20160701062247.GB5358@sigill.intra.peff.net>
In-Reply-To
<20160630193845.TbelqPPHx%steffen@sdaoden.eu>
On Thu, Jun 30, 2016 at 09:38:45PM +0200, Steffen Nurpmeso wrote:
Show 11 quoted lines
> For some time (currently with 2.9.0) know see that a single commit
> gives a longer hash than necessary, even though there is no
> ambiguity:
> 
>   ?0[steffen@wales ]$ git longca|
>   awk 'BEGIN{l7=0;l8=0}\
>     /^[[:alnum:]]{7} /{++l7;next}\
>     /^[[:alnum:]]{8} /{++l8;print}\
>   END{print "L7 " l7 " L8 " l8}'
>   786d0c9c [mimepipe.2] send.c:sendpart(): force iconv(3)+ for TEXT part handlers..
>   L7 3364 L8 1

I don't know what your "git longca" alias is, but presumably it's running "git log". That will show just _commit_ hashes, but the abbreviation code will consider all objects.

There are some places you can use an abbreviated sha1 that know they are looking for a commit, but most places will generally complain if there is ambiguity between a blob and commit (e.g., "git show $foo").

It's also presumably just traversing HEAD, so it would miss commits on other branches.

>   ?0[steffen@wales ]$ git long|cut -f1 -d' '|grep ^786
>   786d0c9c
>   786f219
Try "git rev-list --objects --all | grep ^786d0c9".
-Peff
Previous: Steffen NurpmesoNext: Steffen Nurpmeso
Message 4 of 5 in “--abbrev-commit gives longer hash than necessary”
  1. Steffen NurpmesoJun 30, 2016
  2. Bryan TurnerJun 30, 2016
  3. Steffen NurpmesoJul 1, 2016
  4. Jeff KingJul 1, 2016
  5. Steffen NurpmesoJul 1, 2016

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.