Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make Git mark a file as conflicted?

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?

like image 653
Christian Neverdal Avatar asked May 06 '10 10:05

Christian Neverdal


People also ask

How do I force a merge conflict in Git?

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).

How do you mark a merge conflict as resolved?

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 .

What is a conflicted file in GitHub?

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.


2 Answers

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. :)

like image 53
Gingi Avatar answered Nov 16 '22 00:11

Gingi


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.

like image 22
Jakub Narębski Avatar answered Nov 16 '22 00:11

Jakub Narębski