Search code examples
gitrebase

Revert one patch of git rebase


I'm in the middle of one big rebase with a lot of conflict.

just found out a couple of git rebase --continue before actual I accidentally delete one file instead of another.

How can I go back in pacth and fix this, and then reapply the patch?

Edit: --abort is not a solution as I will have to do ALL the patch again. I want to abort only part of them


Solution

  • Everything in your repo stays there until git sees it's been wholly unreachable, through any ref, for at least a month1.

    So you've done some equivalent of git rebase master topic, with say 26 commits A-Z on topic since the branch, and you did what turns out to be a really bad oops rebasing O and didn't really get the full effect until S:

         A...O...Z        topic
        /
    ...b....*             master
             \
              A2..O2..S2  the inflight rebase with the mistake in the rebased O, O2
    

    Your backout is

    git tag restart O2~
    git rebase --abort
    git rebase --onto restart O^ topic
    

    and now you only have to redo the commits infected by the oops.

    If there are good parts to the commits in the O2~..S2 series, conflict resolutions you want to retrieve, you can tag S2 as well, and then during your redo just check out the good parts from those commits, git checkout -p boneyard~3 -- goodpart1 goodpart2 etc etc (where you've tagged S2 as "boneyard" and the good parts are in P2)

    I've done this, hosed a rebase and had to redo it. I wouldn't be surprised if everyone's done that at one point or another. It's no big deal, even for seemingly horrendous cases like yours.


    1You can force the truncation earlier. Don't Do That.