协慌网

登录 贡献 社区

在拉动期间解决 Git 合并冲突以支持其更改

如何解决 git 合并冲突,支持拉动更改?

基本上我需要从工作树中删除所有冲突的更改,而不必通过git mergetool完成所有冲突,同时保持所有无冲突的更改。最好在拉动时这样做,而不是之后。

答案

git pull -s recursive -X theirs <remoterepo or other repo>

或者,简单地说,对于默认存储库:

git pull -X theirs

如果你已经处于冲突状态......

git checkout --theirs path/to/file

您可以使用递归的 “他们的” 策略选项

git merge --strategy-option theirs

来自男人

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.

    This should not be confused with the ours merge strategy, which does 
    not even look at what the other tree contains at all. It discards 
    everything the other tree did, declaring our history contains all that
    happened in it.

theirs
    This is opposite of ours.

注:由于该男子页称,“我们的” 合并的策略选择是由 “我们的” 合并战略非常不同。

如果你已经处于冲突状态,并且你想接受他们所有人

git checkout --theirs .
git add .

如果你想做相反的事情:

git checkout --ours .
git add .

这是非常激烈的,所以在做之前确保你真的想要像这样擦除所有东西。