Re: How to display "HEAD~*" in "git log"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jul 05, 2022 at 12:25:14PM +0300, Konstantin Khomoutov wrote:

> > because SHA sum is hard to memorize, so I have to use copy and past,
> > which is too boring. So, I wonder if there is a way to let "git log"
> > display commits like following:
> > 
> >   HEAD   <one line commit message>
> >   HEAD~1 <one line commit message>
> > HEAD~2 <one line commit message>
> > HEAD~3 <one line commit message>
> >   ...
> > 
> > With these "HEAD~*", I can easily directly type them and no need to
> > move my fingers out of keyboard.
> 
> You can script this. Provided you have a POSIX-compatible shell (such as
> Bash), the encantation would read something like
> 
>  $ git log --oneline | { n=0; while read line; do printf '%d\t%s\n' $n "$line"; done; }

That will just number the commits linearly as they are printed. If your
history has any branches or merges, eventually it will get out of sync.

You can use "name-rev" to annotate commits with names that respect the
history. It only matches full oids, so try:

  git log --oneline --no-abbrev | git name-rev --stdin

If you want shorter hex oids, you can work around it with "--name-only"
and a custom format:

  git log --format='%h (%H) %s' | git name-rev --stdin --name-only

Note that the names will be based on the nearest branches/tags. You can
use "--refs" to limit it, but sadly there doesn't seem to be a way to
specify just HEAD. That might be a fun and easy feature to add.

And finally, if you really like this, you can configure git-log's pager
to always pipe through name-rev, like this:

  [pager]
        log = "git name-rev --stdin | less"

Then the usual "medium" output from git-log will have the annotations on
the "commit" lines. Arguably git-log ought to be able to do this
internally, but I don't think anybody has ever implemented it (and I
wouldn't be surprised if it's a little challenging, just because you'd
have two traversals going on at once in the same program).

Note that I don't use any of those myself. Long ago I taught my terminal
to do keyboard selection of object ids for cut-and-paste. I think there
are probably solutions for tmux and other programs you can find online.
I shared mine for urxvt a while ago:

  https://lore.kernel.org/git/20170120192539.7jts6xqzx46unn7y@xxxxxxxxxxxxxxxxxxxxx/

though if anybody is interested in it, let me know because I can share a
new version with some bug fixes and improvements since then.

-Peff



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux