如何通过在 Git 中选择远程版本来自动解决合并冲突?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/528659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to automatically resolve merge conflicts by selecting the remote version in Git?
提问by
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?
有没有办法指定 git 通过为每个文件获取远程版本来自动解决一组文件的冲突?比如,获取某个目录下每个文件的远程版本?
回答by David Schmitt
git-mergeseems to support only the "ours" strategy, where the result of a merge is the local version. And that only for the whole tree.
git-merge似乎只支持“ours”策略,其中合并的结果是本地版本。这仅适用于整棵树。
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.
如果你进入了冲突状态,在做合并,你可以使用git的结帐的--theirs
一个路径从索引检索文件。
Finally you can git-resetto force parts of the tree to a specific commit.
最后,您可以git-reset强制树的某些部分进行特定的提交。
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.
现在还有http://www.seanius.net/blog/2011/02/git-merge-s-theirs/基本上建议做一个merge -s ours
然后反向应用更改。
回答by L. Holanda
You can use recursive
strategy (-s) with theirs
option (-X). That is:
您可以将recursive
策略 (-s) 与theirs
选项 (-X) 结合使用。那是:
git merge -s recursive -X theirs source_branch