如何通过在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:34:57  来源:igfitidea点击:

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

gitmergeconflict

提问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 --theirswith 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 oursand 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 recursivestrategy (-s) with theirsoption (-X). That is:

您可以将recursive策略 (-s) 与theirs选项 (-X) 结合使用。那是:

git merge -s recursive -X theirs source_branch