1

我想从存储库中提取,并且我相信该存储库中与我的冲突的任何更改集都是更好的选择。

如何使拉取自动化,这样我就不必处理任何合并冲突,并且我从中拉取的存储库总是能赢得战斗?

查看命令行选项,我不确定是否git pull --squash是我正在寻找的,或者我是否必须应用某种合并策略。我不知道我会传递给什么

-s <strategy>
--strategy=<strategy>

或者

-X <option>
--strategy-option=<option>

如果那确实是我应该使用的标志之一。

4

1 回答 1

5

您正在寻找recursive带有选项的策略theirs

git pull -s recursive -X theirs

从 git-pull 手册页:

recursive

  This can only resolve two heads using a 3-way merge algorithm. When
  there is more than one common ancestor that can be used for 3-way
  merge, it creates a merged tree of the common ancestors and uses that
  as the reference tree for the 3-way merge. This has been reported to
  result in fewer merge conflicts without causing mis-merges by tests
  done on actual merge commits taken from Linux 2.6 kernel development
  history. Additionally this can detect and handle merges involving
  renames. This is the default merge strategy when pulling or merging
  one branch.

The recursive strategy can take the following options:

  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.

    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 the opposite of ours.

然而,这确实不是一个好主意。即使您相信上游的更改是正确的,您如何知道它们与您的更改一起工作而不会导致冲突?

我个人更喜欢git pull --rebase直截了当,git pull并逐个检查每个冲突的提交。

于 2014-01-24T00:25:36.063 回答