It's possible to commit files that contains conflict data. Is there a way to mark these files as conflicted again, so that running git mergetool will generate the necessary files and run the merge tool?
One helpful tool is git checkout with the --conflict option. This will re-checkout the file again and replace the merge conflict markers. This can be useful if you want to reset the markers and try to resolve them again. You can pass --conflict either diff3 or merge (which is the default).
Note the list of conflicted files with: git status (under Unmerged paths section). Solve the conflicts separately for each file by one of the following approaches: Use GUI to solve the conflicts: git mergetool (the easiest way). To accept remote/other version, use: git checkout --theirs path/file .
You can only resolve merge conflicts on GitHub that are caused by competing line changes, such as when people make different changes to the same line of the same file on different branches in your Git repository. For all other types of merge conflicts, you must resolve the conflict locally on the command line.
If the index is already in a conflict state, simply check out the file with the --conflict=merge
flag:
git checkout --conflict=merge file
If the index is clean because the unresolved file has been [erroneously] added, just reset it before checking it out:
git reset file git checkout --conflict=merge file
This will allow you to resume conflict resolution normally (e.g., git mergetool
).
NOTE: Promoting a comment to @jakub-narębski's answer into its own answer by request from @fourpastmidnight. :)
You can get contents of file with conflict markers using git checkout --conflict=merge -- file
, but if you have cleaned up index by using git add file
(or if GUI did that for you) it wouldn't work.
There is git update-index --unresolve
, but it is hacky, and does not work very reliably. I think the state it restores would be not enough for git-mergetool.
You would probably have to redo merge, or use git update-index --cacheinfo
to manually set stages version... git-stash can help you preserve correctly resolved conflicts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With