A small interface over git rebase -i
's common usage
-
Easy non-interactive interactive rebasing with action applied only to specified revision;
-
Allows using
:/<text>
notation easily; -
Uses
--root
if needed to apply action to root commit.
gitreb <action> <revision>
This does the same as calling git rebase -i <revision>^
and then replacing the first word with <action>
in EDITOR.
To use as a git subcommand, insert the following in your .gitconfif
:
[alias]
autorebase = ! /path/to/gitreb/script
You can then do:
git autorebase edit :/some nasty bug
-
If
<revision>
is the root commit, then GitReb does the same as callinggit rebase -i --root
and replacing the first word with<action>
. -
If
<revision>
uses the:/<text>
notation, then GitReb does the same as callinggit rebase -i HEAD^{/<text>}^
.This is not explicitely coded, merely the only side-effect of using
git rev-parse
to find the commit then applying<commit>^
to the result.AFAIK,
:/<text>
is the only notation to which you can't just apply the lone caret modifier.
I wanted to be able to use the following command intuitively:
$ git rebase -i :/<text>^ # DOES NOT DO AS EXPECTED
I wrote this on Stack Overflow which describes the situation.
I also don't like having to use EDITOR for such a simple to describe operation.
This StackOverflow comment
mostly answers both concerns by using git rev-parse
and $GIT_SEQUENCE_EDITOR
with sed -i
.
I was compelled to
- use
ed
which unlikesed
is supposed to edit files in place, - make the script shell-agnostic,
- use default
edit
behaviour instead of always usingreset HEAD^
, (though you could still reuse the selected commit message withcommit -c
, I didn't want the default behaviour to change). - Use
<commit>^
instead of<commit>^^
, - Use
--root
if needed