本文介绍了如何自动解决在当前分支服用版本一个Git冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我得到一个合并冲突富/跳回到bar.txt 运行此时:

Let's suppose that I get a merge conflict on foo/bar.txt when running this:

$ git checkout A
$ git merge B

我想从分支A.采取富/跳回到bar.txt 自动解决冲突(我知道我在做什么,我确实需要此在支路B的版本是错了,我不在乎在这种情况下失去工作树改变)看来,我可以通过运行这些命令做到这一点:

I'd like to automatically resolve the conflict by taking foo/bar.txt from branch A. (I know what I'm doing, and I do need this. The version in branch B is wrong, and I don't care about losing changes in the working tree in this case.) It seems that I can do it by running these commands:

$ git reset    foo/bar.txt
$ git checkout foo/bar.txt

有没有更简单,单一命令的解决方案?

Is there a simpler, single-command solution?

不幸的是这些命令修改富/跳回到bar.txt 即使没有冲突,我不希望出现这种情况。如果没有冲突,我想希望保持富/跳回到bar.txt 在任何状态 git的合并乙已离开吧。

Unfortunately these commands change foo/bar.txt even if there is no conflict, and I don't want that. If there is no conflict, I want want to keep foo/bar.txt in whatever state git merge B has left it.

所以我需要一个Un​​ix shell命令,如果在富/跳回到bar.txt A冲突,将检测,如果有,它会解决因冲突服用富/跳回到bar.txt 的版本,从目前的分支。它不会做任何事情,也就是说,它不会修改其他文件,也不会提交更改,并不会改变富/跳回到bar.txt 如果没有在该文件中没有任何冲突。

So I need a Unix shell command, which would detect if there is a conflict in foo/bar.txt, and if there is, it would resolve the conflict by taking the version of foo/bar.txt from the current branch. It wouldn't do anything else, i.e. it wouldn't modify other files, it wouldn't commit the changes, and it wouldn't change foo/bar.txt if there is no conflict in that file.

推荐答案

如果你想要做它作为一个一次性的,单行的命令是:

If you want to do it as a one-off, the single-line command is:

$ git checkout --ours foo/bar.txt  # <-- resets it only if the merge found conflicts in this file
$ git checkout HEAD -- foo/bar.txt # <-- resets it to that specific version no matter what

要配置Git的合并永久忽略到本地更改的文件的所有上行的变化:

To configure git's merge to permanently ignore all upstream changes to a locally-changed file:

$ git config merge.pin.driver true
$ echo foo/bar.txt merge=pin >> .git/info/attributes

真正以上仅仅是Unix的真正命令,它的成功说,它取得了本地版本看的权利,在这种情况下,这样做没有什么不可以。你当然可以让你的合并命令更复杂。)

(true above is just the unix true command, its success says it made the local version look right, in this case by doing nothing to it. You can of course get more sophisticated with your merge commands.)

我想你不想合并--strategy =我们 - 策略选项=我们那些适用于整个合并。

I think you don't want merge --strategy=ours or --strategy-option=ours, those apply to entire merges.

这篇关于如何自动解决在当前分支服用版本一个Git冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 17:07