小编典典

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

git

如何解决 git 合并冲突以支持拉取更改?

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


阅读 275

收藏
2022-02-19

共3个答案

小编典典

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

git merge --strategy-option theirs

来自man

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.

注意:正如手册页所说,“我们的”合并策略选项与“我们的”合并策略非常不同。

2022-02-19
小编典典

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

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

git pull -X theirs

如果您已经处于冲突状态…

git checkout --theirs path/to/file
2022-02-19
小编典典

如果您已经处于冲突状态,并且您只想接受他们的所有内容:

git checkout --theirs .
git add .

如果你想做相反的事情:

git checkout --ours .
git add .

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

2022-02-19