Search code examples
gitrebase

Git reset current rebase


I've been doing a rebase. I've worked on fixing some conflicts but I've ended up going in the wrong direction and now I just want to start again fixing these conflicts.

I'd like to reset the rebase, so that I'm still rebasing the current commit but the working copy has been reset to when the commit was flagged up with conflicts in the first place.

How can I reset a rebase on the current commit?


Solution

  • If you just want to redo a merge for a specific file, all you need to do is:

    git checkout -m <file>
    

    If you want to redo the whole commit, here's how I do it (there's probably a better way of doing this):

    1. There's a conflict during the rebase
    2. I mess up the conflict resolution
    3. I run a git status which, as of Git 2.0.0, gives me something like this (only if you are doing an interactive rebase):

      interactive rebase in progress; onto 14ed389
      Last command done (1 command done):
         pick db2511c Modify file
      Next command to do (1 remaining command):
         pick d1c2037 Modify file one more time
        (use "git rebase --edit-todo" to view and edit)
      You are currently rebasing branch 'other' on '14ed389'.
        (fix conflicts and then run "git rebase --continue")
        (use "git rebase --skip" to skip this patch)
        (use "git rebase --abort" to check out the original branch)
      
      Unmerged paths:
        (use "git reset HEAD <file>..." to unstage)
        (use "git add <file>..." to mark resolution)
      
              both modified:   file.txt
      
    4. I copy the line for the command the rebase is currently executing: pick db2511c Modify file
    5. I run git rebase --edit-todo and paste the line onto the top of the file
    6. I run git rebase --skip