Abhishek Nikam
Abhishek Nikam

Reputation: 688

Keeping New changes after Git Merge

I tried to merge two branches and there were some files which were not auto-merged. I have conflicts markers in non-merged files for eg:

<<<<<< HEAD int a=4; =========== int a=5; <<<<<<< branch2

If I always want to keep the changes from merged branch in my files i.e. everything below the =======, Is there a command or script way to do it rather than manually editing each file?

Upvotes: 0

Views: 4694

Answers (2)

imsky
imsky

Reputation: 3279

git merge -X ours other_branch will preserve your changes.

git merge -X theirs other_branch will do the opposite.

See https://git-scm.com/docs/git-merge#_merge_strategies

Upvotes: 5

Rmahajan
Rmahajan

Reputation: 1361

If you have merge conflicts in multiple files and based on your decision to keep which file, you can use git commands

git merge master     
Auto-merged default.html
CONFLICT (content): Merge conflict in default.html
Auto-merged index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

you can decide which files you have to keep, for example :

git checkout --theirs default.html
git checkout --ours index.html

Upvotes: 4

Related Questions