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

前端 未结 2 1585
滥情空心
滥情空心 2020-12-22 16:57

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

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-22 17:39

    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".

提交回复
热议问题