Force Git to always choose the newer version during a merge?

拥有回忆 提交于 2019-12-18 10:02:58

问题


Let's assume I merge git and there is a merge conflict.

My question is: how can I force git to always choose the newer version of code in conflict so I won't need to resolve the conflict by hand?


回答1:


It is not exactly the "newer" version, but you can tell git to always prefer the version on the current branch using git merge branch -X ours, or to prefer the version of the branch being merged, using git merge branch -X theirs.

From man git-merge:

ours:

This option forces conflicting hunks to be auto-resolved cleanly by favoring our version. Changes from the other tree that do not conflict with our side are reflected to the merge result. For a binary file, the entire contents are taken from our side.

theirs:

This is the opposite of "ours".




回答2:


I use this,

git fetch --prune
git reset --hard origin/master


来源:https://stackoverflow.com/questions/13594344/force-git-to-always-choose-the-newer-version-during-a-merge

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!