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

Re: 'git log' numbering commits?

From
Jeff King <peff@peff.net>
Date
Apr 12, 2012, 08:41 UTC
Message-ID
<20120412084122.GG31122@sigill.intra.peff.net>
In-Reply-To
<4F868A24.9090004@monom.org>
On Thu, Apr 12, 2012 at 09:54:12AM +0200, Daniel Wagner wrote:
Show 12 quoted lines
> My workflow involves a lot of "git rebase -i". For figuring out which
> commit id to use I do first a 'git log --oneline'. Then I do copy past
> the id to the 'git rebase -i'. The reason why I don't use relative
> id such as HEAD~4, because I keep miscounting the commits.
> 
> So my question is there a magic option to have git log to enumerate the
> commits, e.g.
> 
> 1: 2fcd2b3 network: Remove unused function
> 2: b376b2a session: Fix introspection for Change()
> 3: 15c9cd0 wifi: Refactor desctruction of network object
> 4: a9c699f network: Remove device pointer in network_remove()
No, there is no such feature. You can do this:
  git log --oneline | nl "-s: "

but that will just give you the count of commits shown. If the history is not a single line of development, then those numbers will become meaningless quickly. Also note that there is an off-by-one in this scheme; HEAD~2 will be numbered as "3".

If you wanted to simply decorate each commit with a more readable name, you could do this:

  git log --format='%H: %s' |
  git name-rev --stdin --name-only

though for simplicity, you may find that you prefer to name only based on the current tip. You can do that like this:

  git log --format='%H: %s' |
  git name-rev --stdin --name-only \
    --refs `git symbolic-ref HEAD`
which yields output like:
  your-topic: network: Remove unused function
  your-topic~1: session: Fix introspection for Change()
  your-topic~2: wifi: Refactor desctruction of network object
  your-topic~3: network: Remove device pointer in network_remove()

However, if you really just want this to make "rebase -i" easier, have you considered setting the upstream branch config for your branches? When I create a topic branch, I do:

  git checkout -b topic origin/master

And then "git rebase -i @{upstream}" rebases everything up to my upstream branch (origin/master). That may be slightly more than I want, but it lets me see the whole series in the "rebase -i" sequencer. Recent versions of git even default to "@{upstream}", so you can just say "git rebase -i".

How do you usually create your branches? What version of git are you using (the "@{upstream}" default is in v1.7.6 and later)?

-Peff
Previous: Daniel WagnerNext: Daniel Wagner
Message 2 of 4 in “'git log' numbering commits?”
  1. Daniel WagnerApr 12, 2012
  2. Jeff KingApr 12, 2012
  3. Daniel WagnerApr 12, 2012
  4. Philippe VaucherApr 12, 2012

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.