Git 合并使用递归策略和耐心选项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5024402/
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
Git merge using recursive strategy and patience option
提问by Filip Zawada
How to merge a branch with git using patience option provided by the recursive strategy? I'm using git version 1.7.3.1.msysgit.0
如何使用递归策略提供的耐心选项将分支与 git 合并?我正在使用 git 版本 1.7.3.1.msysgit.0
Even docs are not consistent and, what's more, differ from what the actual command outputs.
甚至文档也不一致,而且与实际命令输出的内容不同。
git merge [-s
<strategy>
] [-X<strategy-option>
]<commit>
git合并 [-s
<strategy>
] [-X<strategy-option>
]<commit>
and further in text:
并进一步在文本中:
-X
<option>
-X
<option>
(no space)
(没有空间)
Output from the command says:
命令的输出说:
-X, --strategy-option <option=value>
option for selected merge strategy
So I tried a couple versions with following results:
所以我尝试了几个版本,结果如下:
$ git merge -s recursive -Xpatience sourceBranch
fatal: Unknown option for merge-recursive: -Xpatience
$ git merge -X patience sourceBranch
fatal: Unknown option for merge-recursive: -Xpatience
$ git merge -Xpatience sourceBranch
fatal: Unknown option for merge-recursive: -Xpatience
$ git merge --strategy-option patience sourceBranch
fatal: Unknown option for merge-recursive: -Xpatience
$ git merge -X option=patience sourceBranch
fatal: Unknown option for merge-recursive: -Xoption=patience
$ git merge --strategy-option option=patience sourceBranch
fatal: Unknown option for merge-recursive: -Xoption=patience
$ git merge option=patience sourceBranch
fatal: 'option=patience' does not point to a commit
$ git merge -X option=patience sourceBranch
fatal: Unknown option for merge-recursive: -Xoption=patience
It looks as if the option's not implemented...
看起来好像选项没有实现......
回答by Mark Longair
The --patience
option for git merge-recursive
was introduced in commit 58a1ece478c6038a7eb0b6e494d563bd5e6d5978
. You can find out in a clone of git.git
what versions contain this change with git tag --contains 58a1ece478
:
在--patience
供选择git merge-recursive
的承诺被引入58a1ece478c6038a7eb0b6e494d563bd5e6d5978
。您可以在克隆中找到git.git
包含此更改的版本git tag --contains 58a1ece478
:
v1.7.4
v1.7.4-rc0
v1.7.4-rc1
v1.7.4-rc2
v1.7.4-rc3
v1.7.4.1
So I suspect that you're just using a slightly too old version of mSysGit. There is a preview version of 1.7.4 available now - I think you should try that one.
所以我怀疑你只是使用了一个稍微太旧的 mSysGit 版本。现在有一个 1.7.4 的预览版 - 我想你应该试试那个。
I've just tried this with git version 1.7.4, and the following command line syntax works for me:
我刚刚在 git 版本 1.7.4 上尝试过这个,下面的命令行语法对我有用:
git merge -s recursive -X patience other-branch
回答by VonC
I see here the patchintroducing the patience option to the recursive merge strategy, base on Git1.7.2.2, but I don't see it in any of the subsequent release notes.
我在这里看到了基于 Git1.7.2.2 为递归合并策略引入耐心选项的补丁,但我没有在任何后续发行说明中看到它。
Yet the patience diff algorithm has been presented since 2009, and is detailed here.
然而,耐心差异算法自 2009 年以来就已提出,并在此处进行了详细说明。
> grep -i patience *.c
diff.c: else if (!strcmp(arg, "--patience"))
diff.c: DIFF_XDL_SET(options, PATIENCE_DIFF);
merge-recursive.c: else if (!strcmp(s, "patience"))
merge-recursive.c: o->xdl_opts |= XDF_PATIENCE_DIFF;
The merge command should understand this option... but this function below seems to never be called (not anywhere in merge-recursive.c
or in any other *.c
file!):
合并命令应该理解这个选项......但下面的这个函数似乎永远不会被调用(不在merge-recursive.c
任何其他*.c
文件中或任何其他文件中!):
int parse_merge_opt(struct merge_options *o, const char *s)
{
if (!s || !*s)
return -1;
if (!strcmp(s, "ours"))
o->recursive_variant = MERGE_RECURSIVE_OURS;
else if (!strcmp(s, "theirs"))
o->recursive_variant = MERGE_RECURSIVE_THEIRS;
else if (!strcmp(s, "subtree"))
o->subtree_shift = "";
else if (!prefixcmp(s, "subtree="))
o->subtree_shift = s + strlen("subtree=");
else if (!strcmp(s, "patience"))
o->xdl_opts |= XDF_PATIENCE_DIFF;
else if (!strcmp(s, "ignore-space-change"))
o->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE;
else if (!strcmp(s, "ignore-all-space"))
o->xdl_opts |= XDF_IGNORE_WHITESPACE;
else if (!strcmp(s, "ignore-space-at-eol"))
o->xdl_opts |= XDF_IGNORE_WHITESPACE_AT_EOL;
else if (!strcmp(s, "renormalize"))
o->renormalize = 1;
else if (!strcmp(s, "no-renormalize"))
o->renormalize = 0;
else if (!prefixcmp(s, "rename-threshold=")) {
const char *score = s + strlen("rename-threshold=");
if ((o->rename_score = parse_rename_score(&score)) == -1 || *score != 0)
return -1;
}
else
return -1;
return 0;
}
The "Unknown option" error message is only printed by the handle_options
function in git.c
.
And XDF_PATIENCE_DIFF
doesn't show anywhere else in git sources (1.7.4)... so yes, I don't know how this could be implemented for the merge.
“未知选项”错误消息仅由印刷handle_options
在功能git.c
。
并且XDF_PATIENCE_DIFF
没有在 git 源 (1.7.4) 中的其他任何地方显示......所以是的,我不知道如何为合并实现这一点。