I have a real bugger of a conflict resolution set, and I figured that I'd just go for it and if I failed, then I should be able to bring back the file into its conflict state. However, I can't seem to find a way to go back. git is still in MERGING state, so how do I backup a single file and reresolve?
-
Did you pushed your file to your branch before pulling? – RICKY KUMAR Jan 12 '18 at 00:34
-
@RICKYKUMAR, Not sure what you mean. I have a lot of modifications to the file set. I did a `git merge branch_name`. Then I did a `git mergetool`. Now I want to undo a particular file. Am I going to have to do a hard reset to that file and remerge? Not even sure if that's possible to do on a single file. – Adrian Jan 12 '18 at 00:41
1 Answers
First, if you think you might have a decent resolution (or part of it), copy the file somewhere else. :-) Then just run:
git checkout -m -- path
(the --
part is needed only if the file's path
resembles a valid git checkout
option, e.g., if the file you want to put back in conflicted state is named --theirs
or -f
or some such). This will re-create the conflict-marker variant of the file from the three inputs (merge base and both branch heads), and write that file to the work-tree.
Note that you can specify the --conflict=merge
(default) style, or the --conflict=diff3
style. This is the same as setting merge.conflictStyle
in .gitconfig
, but just for that one file and this one checkout.
If you (or git mergetool
) used a merge tool that already ran git add
on the resolved variant, note that this puts the file back into conflicted state, i.e., it restores the three higher stage entries into the index. You can now run git mergetool
again, or—my personal preference—just manually edit the conflicted file and git add
the resulting work-tree copy once you are satisfied that it is correct.

- 448,244
- 59
- 642
- 775
-
It was the `git checkout -m -- path` that was the piece of the puzzle I was missing. Thanks. – Adrian Jan 12 '18 at 01:12
-
Hm. You should only get this by running either `git merge` or `git pull`, not by running `git checkout -m`. – torek Jan 12 '18 at 01:36
-
Yeah, edited a line in the command line history. Didn't see the `merge` command. – Adrian Jan 12 '18 at 01:37
-
After `git checkout -m upstream/save -- README.md` as a single test file, `git mergetool` returns "No files need merging" :( while `git diff HEAD` shows the changes, some unwanted. How can I force the mergetool GUI to run, allowing me to selectively choose edits from either B or C side? (A being _base_) – Marcos May 22 '19 at 10:39
-
2@Marcos: `git checkout -m` behaves differently if you're not still in a merge, vs if you are. If you *are* still in an incomplete merge—i.e., you haven't concluded th merge with `git commit` or `git merge --continue`—you would run `git checkout -m -- README.md` to restore it to unmerged state. I'm not sure what happens if you name a commit as well. – torek May 22 '19 at 15:18