Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always use version from merged branch on conflicts

Currently I am working in a feature branch that will soon be merged back into master. I recently tried just that and had some merge conflicts, which I had to fix manually.

So, is it possible to tell git to always use the version from the merged branch in order to avoid merge conflicts beforehand? In this case I fixed the conflicts manually but always chose the version from the merged branch, so this would save me some tedious work.

like image 715
Max Avatar asked May 28 '11 07:05

Max


People also ask

What happens if you get a conflict during a merge?

A merge conflict is an event that occurs when Git is unable to automatically resolve differences in code between two commits. When all the changes in the code occur on different lines or in different files, Git will successfully merge commits without your help.

Can Git automatically resolve merge conflicts?

When you pull or merge branches, Git will select the recursive strategy as default. The recursive strategy only can detect and do merges which involve renames, but cannot use detected copies. The ours option forces conflicted parts to be automatically resolved by favoring 'our' version.


1 Answers

You can do exactly this in git with the following command, assuming that feature is the name of your feature branch:

git merge -s recursive -X theirs feature

This says to use the "recursive" merge strategy, but with the "theirs" option. This means that when there is a conflict, it will be automatically resolved by taking the version of the hunk from the feature branch, not your current branch. (Note that this is completely different from the "theirs" merge strategy, which has now been removed from git.)

This feature was introduced in git v1.7.0.

like image 59
Mark Longair Avatar answered Oct 28 '22 13:10

Mark Longair