Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
918 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...