33

因此,由于某种原因,我与新的合并修补程序发生了很多冲突。实际 [手动] 更改的文件没有冲突。所有的冲突都在修复期间未触及的文件中,显然它是空格的问题。我稍后会尝试解决这个问题,但现在我需要合并修补程序并进行部署。

如何解决所有冲突以使用 HEAD 版本?我不想逐个文件。是的,我知道这是一种不好的做法,但冲突都是空格,我知道 HEAD 是正确的——通过所有测试并在生产中运行良好。

有任何想法吗?

我正在使用 OSX。

4

3 回答 3

70
git merge -Xours origin/master

将与origin/master(相同的事情git pull origin master)进行合并,并将通过从本地分支获取版本来解决任何冲突。

如果您已经完成了错误合并,则可以先将所有内容重置为头部git reset --hard HEAD

在这种情况下,你应该这样做

git reset --hard HEAD
git merge -Xours origin/master

那应该可以解决您的问题!

(也值得一提,-Xtheirs会做同样的事情,但在任何冲突中取上游版本。)


此外,冲突很可能是因为上游版本使用 windows 样式的行尾,而您在本地计算机上编辑文件的任何程序都使用 mac 样式或 linux 样式的行尾。

您可以在 git 中设置一些选项以始终提交 windows 样式或 linux 样式的行尾,但始终在您的工作目录中签出 mac-style 或 linux-style。

有关更多信息,请参阅此链接: https ://help.github.com/articles/dealing-with-line-endings

于 2013-11-26T22:28:10.523 回答
11

如果您的本地分支有冲突,您可以简单地运行以下命令:

git checkout --conflict=merge .
git checkout --ours .

使用本地分支解决冲突。

于 2018-09-13T12:36:41.493 回答
6

我会:

$ git checkout master   # or where ever you want to merge the hotfix into
$ git merge --no-commit -Xours <hotfix-branch>
$ git status    # make sure the only change is the file you wanted
$ git diff      # make sure they changes are what you wanted
$ git commit -m "<your merge message"

这将使用默认的递归策略拉入任何不冲突的文件,但它将通过简单地使用 master/HEAD 版本来解决任何冲突的文件。文档:

$ git merge --help
....

   recursive
       ... 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. ....
于 2013-11-26T22:37:18.400 回答