-1

由于愚蠢,大文件的唯一版本是尝试合并,即它包含很多行,例如

<<<<<<< HEAD        double[] p1 = ...
                    double[] p2 = ...
=======         double[] p1 = ...
                double[] p2 = ...
>>>>>>> origin/foo

我如何摆脱这些,而不必编辑每一个,总是选择HEAD

合并和一些愚蠢的命令让我失去了原来 HEAD 的踪迹,但幸运的是 git reflog 帮助我找到了合并之前的位置。

4

2 回答 2

1

如果您想始终选择 HEAD,那么您正在寻找一个merge strategy被调用的ours.

git merge -s ours <branch-to-merge>

在合并时引用 git help:

合并策略 合并机制(git-merge 和 git-pull 命令)允许使用 -s 选项选择后端合并策略。一些策略也可以采用自己的选项,可以通过将 -X 参数传递给 git-merge 和/或 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.

           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.

   ours
       This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head,
       effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of
       side branches. Note that this is different from the -Xours option to the recursive merge strategy.

这些是列出的一些策略。用于git help merge寻找更多。

于 2012-07-31T11:53:00.043 回答
0

您可以在合并时通过传递-X ignore-space-change到命令行来忽略空间更改,这也适用于git rebase.

于 2012-07-31T11:17:51.580 回答