How to automatically resolve merge conflicts by selecting the remote version in Git?

丶灬走出姿态 提交于 2020-01-21 02:44:11

问题


Is there any way to specify to git to automatically resolve the conflicts for a pack of files by taking the remote version for each of them? For instance, to take the remote version of each files in a certain directory?


回答1:


git-merge seems to support only the "ours" strategy, where the result of a merge is the local version. And that only for the whole tree.

If you enter a conflicted state while doing a merge, you can use git-checkout's --theirs with a path to retrieve files from the index.

Finally you can git-reset to force parts of the tree to a specific commit.

There's now also http://www.seanius.net/blog/2011/02/git-merge-s-theirs/ who basically recommends making a merge -s ours and then reverse-apply the changes.




回答2:


You can use recursive strategy (-s) with theirs option (-X). That is:

git merge -s recursive -X theirs source_branch


来源:https://stackoverflow.com/questions/528659/how-to-automatically-resolve-merge-conflicts-by-selecting-the-remote-version-in

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