leo*_*sas 20 git git-merge opendiff
因此,由于某些原因,我与新的合并修补程序发生了很多冲突.实际上[手动]更改的文件没有冲突.所有冲突都存在于修复期间未触及的文件中,显然是空白问题.我稍后会尝试解决该问题,但现在我需要合并修补程序和部署.
如何解决所有冲突以使用HEAD版本?我不想一个接一个地去.是的,我知道这是一个不好的做法,但冲突都是空白,我知道HEAD是正确的 - 通过所有测试并在生产中运行良好.
有任何想法吗?
我正在使用OSX.
NHD*_*aly 43
git merge -Xours origin/master
Run Code Online (Sandbox Code Playgroud)
将进行合并origin/master(同样的事情git pull origin master)并通过从本地分支获取版本来解决任何冲突.
如果你已经完成了错误的合并,你可以先将所有内容重置到头部git reset --hard HEAD.
在那种情况下,你应该这样做
git reset --hard HEAD
git merge -Xours origin/master
Run Code Online (Sandbox Code Playgroud)
这应该可以解决你的问题!
(也值得一提的是,它-Xtheirs会做同样的事情,但在任何冲突中都采用上游版本.)
此外,最有可能的冲突是因为上游版本使用的是Windows样式的行结尾,而且您在本地计算机上编辑文件的任何程序都使用mac样式或linux样式的行结尾.
您可以在git中设置选项以始终提交Windows样式或Linux样式的行结尾,但始终在工作目录中检出mac-style或linux-style.
有关详细信息,请参阅此链接:https: //help.github.com/articles/dealing-with-line-endings
我会:
$ 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"
Run Code Online (Sandbox Code Playgroud)
这将在任何非冲突文件中使用默认递归策略拉取,但它会通过简单地使用 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. ....
Run Code Online (Sandbox Code Playgroud)
小智 5
如果您的本地分支机构存在冲突,则可以简单地运行以下命令:
git checkout --conflict=merge .
git checkout --ours .
Run Code Online (Sandbox Code Playgroud)
使用本地分支机构解决冲突。