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

Re: Any way to make git-log to enumerate commits?

From
Elijah Newren <newren@gmail.com>
Date
Dec 5, 2018, 15:31 UTC
Message-ID
<CABPp-BHhYgBndaOjTC9-YQ5gNJXqaw21Hf=FZzyA7AKDQvN+0A@mail.gmail.com>
In-Reply-To
<20181205145419.vbbaghzzrnceez45@tigra>
On Wed, Dec 5, 2018 at 6:56 AM Konstantin Khomoutov <kostix@bswap.ru> wrote:
Show 33 quoted lines
>
> On Wed, Dec 05, 2018 at 05:22:14PM +0300, Konstantin Kharlamov wrote:
>
> > It would be great if git-log has a formatting option to insert an
> > index of the current commit since HEAD.
> >
> > It would allow after quitting the git-log to immediately fire up "git
> > rebase -i HEAD~index" instead of "git rebase -i
> > go-copy-paste-this-long-number-id".
>
> This may have little sense in a general case as the history maintained
> by Git is a graph, not a single line. Hence your prospective approach
> would only work for cases like `git log` called with the
> "--first-parent" command-line option.
>
> Still, for a simple approach you may code it right away yourself.
> Say, let's create an alias:
>
>   $ git config alias.foo '!git log "$@" --pretty=oneline --source | {
>       n=0;
>       while read sha ref rest; do
>         printf "%s\t%s~%s\t%s\n" "$sha" "$ref" $n "$rest"
>                 n=$((n+1))
>           done
>     }'
>
> Now calling `git foo --abbrev=commit` would output something like
>
> 9be8e297d        HEAD~7       Frobincated fizzle
>
> where "7" is what you're looking for.
>
> A more roubst solution may need to use the `git rev-list` command.
Or, just use name-rev so it works with non-linear histories too:
git log | git name-rev --refs=$(git symbolic-ref HEAD) --stdin | less

That'll add things like "master~7" for stuff in the first parent history and output like "master~7^2~3" for commits on side-branches, either of which can be fed to other git commands.

Previous: Konstantin KhomoutovNext: Andreas Schwab
Message 3 of 7 in “Any way to make git-log to enumerate commits?”
  1. Konstantin KharlamovDec 5, 2018
  2. Konstantin KhomoutovDec 5, 2018
  3. Elijah NewrenDec 5, 2018
  4. Andreas SchwabDec 5, 2018
  5. Junio C HamanoDec 6, 2018
  6. Konstantin KhomoutovDec 6, 2018
  7. Junio C HamanoDec 7, 2018

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.