How to automatically resolve a Git conflict by taking the version in the current branch?

纵然是瞬间 提交于 2019-12-02 20:38:20

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

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

(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.)

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

You can specify the merge strategy option ours to the recursive (the default) merge strategy. It will do a normal merge, but in case of conflicting hunks will choose the version of the current branch.

git checkout A
git merge -Xours B
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!