All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Konstantin Kharlamov <hi-angel@yandex.ru>
Cc: git@vger.kernel.org
Subject: Re: How to interactively rebase-and-reword nth commit?
Date: Wed, 25 Aug 2021 17:01:18 +0200	[thread overview]
Message-ID: <87pmu1czn7.fsf@evledraar.gmail.com> (raw)
In-Reply-To: <eda317b080a2e75a170c051c339a76115cce5ad7.camel@yandex.ru>


On Wed, Aug 25 2021, Konstantin Kharlamov wrote:

> I think, one of the most frequent git features used is `rebase -i`. There's a common
> workflow I think everyone knows: you have commits 1, 2, 3, then you decide "Nah, 2nd
> commit needs a change", so you do `git rebase -i HEAD~2`, then in popped up editor
> you modify the `pick` on the first line to become `edit`, then you do the change,
> then `git rebase --continue`.
>
> The boilerplate part here: even though you know that you want to edit HEAD~2, there
> is no way to tell git that right away. Every time you have to launch editor, edit the
> line manually, then save it, close it.
>
> I have seen here some discussions about improving that, someone even posted patches,
> but I'm not aware if it went anywhere. So I created 2 years ago a shell wrapper
> `rebase-at`¹, which upon called as `rebase-at e HEAD~2`, does the thing described
> above automatically. Under the hood I simply substitute EDITOR with `sed` command
> that replaces `pick` on the first line (the HEAD~2 commit) with `e`. If used with
> shell autocompletion, it is now practically instantaneous.
>
> I'm almost happy with `rebase-at`, except I don't know of any way to make it work
> with `reword` git action. You see, "rewording a commit" requires to run EDITOR twice:
> first to substitute `pick` with `reword`, and then to actually edit the commit
> message. But since EDITOR was substituted with sed, the 2nd run won't give you an
> actual editor to change the commit message.
>
> Any ideas, how can I tell `git` that I want to "reword" nth commit right away? Sure,
> I am not the first one to stumble upon it, am I? Any ideas?
>
> 1: https://github.com/Hi-Angel/dotfiles/blob/0b9418224e4ce7c9783dbc2d9473fd1991b9b0b2/.zshrc#L148-L160

Have your GIT_EDITOR do one thing or the other depending on whether it's
asked to edit git-rebase-todo. This works for me:
    
    # rebase-at <action> <comit-ids-and-co>
    function rebase-at() {
        local action=$1
        shift 1
        GIT_EDITOR='perl -MFile::Basename=basename -wE '"'"'
            my $f = shift;
    	exec qw[sed -i -E], q[1s/\\w+/'$action'/], $f
    	    if basename($f) eq q[git-rebase-todo];
            exec "$ENV{EDITOR} $f";
        '"'" git rebase -i "$@"
    }

  reply	other threads:[~2021-08-25 15:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-25 14:06 How to interactively rebase-and-reword nth commit? Konstantin Kharlamov
2021-08-25 15:01 ` Ævar Arnfjörð Bjarmason [this message]
2021-08-25 15:54 ` Martin Ågren
2021-08-25 16:32   ` Konstantin Kharlamov
2021-08-26  6:28 ` ZheNing Hu
2021-08-27  2:04 ` Jeff King
2021-08-27  9:18   ` Konstantin Kharlamov

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=87pmu1czn7.fsf@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=hi-angel@yandex.ru \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.