强制 Git 在合并期间始终选择较新的版本? [英] Force Git to always choose the newer version during a merge?
问题描述
假设我 merge
git 并且存在合并冲突.
Let's assume I merge
git and there is a merge conflict.
我的问题是:如何强制 git 总是选择发生冲突的较新版本的代码,这样我就不需要手动解决冲突?
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?
推荐答案
它不完全是较新"的版本,但是你可以使用 git merge branch -X 告诉 git 总是喜欢当前分支上的版本我们的
,或者更喜欢被合并的分支的版本,使用git merge branch -X theirs
.
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
.
来自man git-merge
:
我们的:
此选项通过支持我们的版本强制自动解决冲突的大块头.来自另一棵树的变化与我方的冲突反映在合并结果上.对于二进制文件,全部内容取自我们这边.
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.
他们的:
这与我们的"相反.
这篇关于强制 Git 在合并期间始终选择较新的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!