Let's say I did a git merge and have a conflict in some file, say package.json
or pom.xml
, and perhaps some other files.
I would like to
- automatically resolve merge conflicts for certain files from command line, while
- letting myself resolve manually all the other conflicts, if any, and
- making sure I don't lose valuable changes from any branch.
Because of 2), I can't use git merge -Xours
as this would resolve all conflicts. I want to resolve only conflicts in one particular file.
Because of 3), I can't use git checkout --ours package.json
as this might lose some changes from the input branch.
The use case is for instance: auto-merging script that will resolve trivial well-known conflicts in a predefined way, and fail if there are some other conflicts in other files.
The typical case I often have is having two branches with version
field in package.json
diverged like below:
$ git diff
diff --cc package.json
index 75c469b,f709434..0000000
--- a/package.json
+++ b/package.json
@@@ -1,6 -1,6 +1,12 @@@
{
"name": "test",
++<<<<<<< HEAD
+ "version": "2.0.1",
++||||||| merged common ancestors
++ "version": "1.0.0",
++=======
+ "version": "1.0.2",
++>>>>>>> master
Is it possible to resolve the conflict for just one file, using given strategy? Something like:
git-resolve-conflict --ours package.json