When git merge
has conflicts, the files that are in a conflicting state contain markers showing the differences.
Suppose that while trying to resolve a conflict, I've made changes, perhaps:
main
and some from mybranch
git checkout mybranch somefile
, thinking "I'll just use the version that's on mybranch
But then I have second thoughts, and I want to put the file back the way it was at the start of the merge, showing the conflict markers, and start over trying to resolve the conflicts.
I'm guessing I can run git checkout [something] somefile
to get back to the conflicting state. What would it be?
Use the --merge
option (-m
in short form) for git checkout
or git restore
(both commands behave the same here)
# the legacy way
git checkout -m <path>
# the (not so) new way
git restore -m <path>
With -m, changes made to the working tree file can be discarded to re-create the original conflicted merge result.