Home > OS >  git: jump back again during interactive rebase
git: jump back again during interactive rebase

Time:10-23

is there a trick to go back again during an interactive git rebase? Let's say something like this:

git init

for c in a b c; do
    touch $c && git add $c && git commit -m $c
done

Now let's say I start some interactive rebase like this:

git rebase -i --root
# p 5e2df3f a
# e b87116d b
# p a55558f c

And, after editing b to my likings - maybe by splitting it into two commits after a git reset HEAD^ -p, I end up with:

git commit --amend
touch b2 && git add b2 git commit -m "b''"
git log --oneline 
# a5f42cc (HEAD) b''
# 5446996 b'
# 5e2df3f a

how can I now jump back without first having to finish the rebase up until the end? I.e. right at this stage I would see:

git rebase --edit-todo
# p a55558f c

But what if I made a mistake in my new 5446996 b' commit? What if I realize I have to amend something else in 5e2df3f a that was originally the start of my rebase edit todo?

Can I somehow jump back - like a nested git rebase -i (which isn't allowed directly)? Or is there some other means to achieve this?

I explicitly do not want to have to finish the rebase I'm in and then restart it again.

Thanks!

CodePudding user response:

You just replay manually what a nested rebase would do. That is, you can just go back to the commit and fix it up:

git checkout 5446996
# edit
git commit -a --amend

Then you cherry-pick the remaining commit(s):

git cherry-pick 5446996..a5f42cc

If necessary, fixup conflicts and git cherry-pick --continue.

Then finish your rebase with git rebase --continue.

  •  Tags:  
  • git
  • Related