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

Re: [PATCH v2] add --abbrev to 'git cherry'

From
Markus Heidelberg <markus.heidelberg@web.de>
Date
May 30, 2009, 16:26 UTC
Message-ID
<200905301826.11924.markus.heidelberg@web.de>
In-Reply-To
<20090530140349.GA25265@unpythonic.net>
Jeff Epler, 30.05.2009:
>  Documentation/git-cherry.txt |    5 ++++-
>  builtin-log.c                |   24 +++++++++++++++++++-----
>  2 files changed, 23 insertions(+), 6 deletions(-)
You could also add --abbrev= to the bash completion.
Show 10 quoted lines
> diff --git a/Documentation/git-cherry.txt b/Documentation/git-cherry.txt
> index 7deefda..5c03da0 100644
> --- a/Documentation/git-cherry.txt
> +++ b/Documentation/git-cherry.txt
> @@ -49,6 +49,9 @@ OPTIONS
>  -v::
>  	Verbose.
>  
> +--abbrev[=<n>]::
> +	Abbreviate commit ids to the given number of characters

The full stop is missing :) And you could add "The default value is 7." as in the git-branch docs. Or even copy the whole description from there for consistency, it also mentions that this sets the minimum length, the displayed SHA1 may be longer, but more about this below.

Show 18 quoted lines
> diff --git a/builtin-log.c b/builtin-log.c
> index f10cfeb..1f3093e 100644
> --- a/builtin-log.c
> +++ b/builtin-log.c
> @@ -1218,12 +1232,12 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
>  			struct strbuf buf = STRBUF_INIT;
>  			pretty_print_commit(CMIT_FMT_ONELINE, commit,
>  			                    &buf, 0, NULL, NULL, 0, 0);
> -			printf("%c %s %s\n", sign,
> +			printf("%c %.*s %s\n", sign, abbrev,
>  			       sha1_to_hex(commit->object.sha1), buf.buf);
>  			strbuf_release(&buf);
>  		}
>  		else {
> -			printf("%c %s\n", sign,
> +			printf("%c %.*s\n", sign, abbrev,
>  			       sha1_to_hex(commit->object.sha1));
>  		}

There is no test for unique ids. "git cherry --abbrev=4" always prints 4 chars per SHA1, so "git show" on these SHA1s mostly gives "error: short SHA1 xxxx is ambiguous." in git.git.

find_unique_abbrev() will help.
Markus
Previous: Jeff EplerNext: Jeff Epler
Message 2 of 9 in “add --abbrev to 'git cherry'”
  1. add --abbrev to 'git cherry'Jeff Epler, May 30, 2009
  2. Markus HeidelbergMay 30, 2009
  3. add --abbrev to 'git cherry'Jeff Epler, May 30, 2009
  4. Stephen BoydMay 30, 2009
  5. Junio C HamanoMay 30, 2009
  6. Markus HeidelbergMay 30, 2009
  7. Junio C HamanoMay 31, 2009
  8. Stephen BoydMay 31, 2009
  9. Jeff EplerJun 1, 2009

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.