git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Konstantin Khomoutov <kostix@bswap.ru>
To: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn>
Cc: git@vger.kernel.org
Subject: Re: How to display "HEAD~*" in "git log"
Date: Tue, 5 Jul 2022 12:25:14 +0300	[thread overview]
Message-ID: <20220705092514.hsm7cou5bqvajvgq@carbon> (raw)
In-Reply-To: <17411d88-b27a-2d20-623d-85c49dc7754e@mails.ucas.ac.cn>

On Tue, Jul 05, 2022 at 03:11:49PM +0800, wuzhouhui wrote:

> I frequently use "git rebase" to move commit to a specific location, to
> know which commit ID as param of "git rebase", I have to list all commits
> by "git log --oneline", then copy specific commit ID, and executing "git
> rebase" as
> 
>   git rebase -i <copied commit ID>~
> 
> 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; }

This is admittedly not convenient so it makes sense to turn into an alias:

 [alias]
   relog = "!relog() { git log --oneline \"$@\" | { n=0; while read line; do printf 'HEAD~%d\t%s\n' $n \"$line\"; n=$((n+1)); done; }; }; relog"

Then the call

 $ git relog

would output something like

HEAD~0	deadbeef Commit message
HEAD~1	fadedfac Another commit message
HEAD~2  12345678 Yet another commit message

...and so on.

It's easy to make that script not output "~0" for the very first entry and
output just "~" instead of "~1" for the second, but I what's presented is
enough for an example.

  reply	other threads:[~2022-07-05  9:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-05  7:11 How to display "HEAD~*" in "git log" wuzhouhui
2022-07-05  9:25 ` Konstantin Khomoutov [this message]
2022-07-05  9:30   ` Konstantin Khomoutov
2022-07-05  9:36     ` wuzhouhui
2022-07-06 12:38       ` kostix
2022-07-06 14:38   ` Jeff King
2022-07-06 16:28     ` Konstantin Khomoutov
2022-07-06 16:49       ` Jeff King
2022-07-06 18:21         ` Konstantin Khomoutov
2022-07-07 17:06           ` Jeff King
2022-07-06 17:31     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220705092514.hsm7cou5bqvajvgq@carbon \
    --to=kostix@bswap.ru \
    --cc=git@vger.kernel.org \
    --cc=wuzhouhui14@mails.ucas.ac.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).