During an interactive rebase, how do you restart the current merge conflict without aborting the entire rebase? [duplicate]

I’m working on an interactive rebase. I’ve --continued 3 times, but confused myself on this current merge conflict and want to start over. How do I restart this merge conflict without losing all my previous work?

I’ve annotated what git status says:

interactive rebase in progress; onto 44444
Last commands done (2 commands done):
   pick 3333333 My edits
   pick 2222222 Removed some gibberish
Next commands to do (8 remaining commands):
   pick 1111111 Personal changes
   # not sure what this is, but what little research I've done makes it seem irrelevant
  (use "git rebase --edit-todo" to view and edit) 
You are currently rebasing branch 'branch' on '44444'.
  (fix conflicts and then run "git rebase --continue")
  # I don't want to skip, I want to restart
  (use "git rebase --skip" to skip this patch)
  # I don't want to go all the way back to the beginning, I only want to restart the 44444 merge conflict.
  (use "git rebase --abort" to check out the original branch)

Unmerged paths:
  # this didn't revert my merge conflict changes
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution) 
        both modified:   file.py

After git restore --staged, I tried again without the --stage. Now it says nothing to commit, working tree clean.

How do I reset only this merge conflict?

  • @mkrieger1 tbh, I’m not sure. This potential dupe is about merge. Does it apply to rebase?

    – 




  • @mkrieger1 okay I tried git checkout -m -- file.txt from one of those answers and it did what I want. Thanks

    – 

I’m not sure if this is a straight up duplicate or a different question with the same answer, but doing this to the file put the commit back into its original merge conflict state:

git checkout -m -- file.txt

Here’s the official documentation on checkout -m:

  -m, --merge

When switching branches, if you have local modifications to one or more files that are different between the current branch and the branch to which you are switching, the command refuses to switch branches in order to preserve your modifications in context. However, with this option, a three-way merge between the current branch, your working tree contents, and the new branch is done, and you will be on the new branch.

When a merge conflict happens, the index entries for conflicting paths are left unmerged, and you need to resolve the conflicts and mark the resolved paths with git add (or git rm if the merge should result in deletion of the path).

When checking out paths from the index, this option lets you recreate the conflicted merge in the specified paths.

When switching branches with –merge, staged changes may be lost.

You can do this to revert all files at once:

git checkout -m -- .

Leave a Comment