Git rebase:传递多个策略选项

3

使用git rebase时,可以通过-X <strategy-option>--strategy-option=<strategy-option>传递合并策略选项。然而,从手册页面无法确定是否可以传递多个选项(如果后续选项替换了先前的选项),如果是,则正确的语法是-X <opt1,opt2>还是-X <opt1> -X <opt2>。运行git rebase --verbose -m -X <opt1> -X <opt2> <upstream>不会产生错误,但即使启用了详细输出,也没有指示是否应用了两个选项或仅应用了最后一个选项。

1个回答

3

opt1,opt2,opt3 逗号分隔的语法用于 git diff

D:\git\git\t>grep -E "\-X" *.sh|grep "\,"
t4047-diff-dirstat.sh:  test_must_fail git show -X=20,cumulative
t4047-diff-dirstat.sh:test_expect_success 'explicit defaults: -Xchanges,noncumulative,3' '
t4047-diff-dirstat.sh:  git diff -Xchanges,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&

不适用于合并/变基中的策略选项。

对于这些选项,需要多个-Xopt1 -Xopt2

但我只能找到一个实例来测试这种语法,而且是失败的情况:t3418-rebase-continue.sh

test_must_fail git rebase -i -s funny -Xopt -Xfoo master topic

实际上,我不确定这是否会被使用。

最初提交(2009年11月,Git v1.7.0-rc0)引入了-X选项,但只测试了一个策略选项。

我看到一个例子,使用了git cherry-pick:

D:\git\git\t>grep -E“-X.*?-X”*.sh

t3418-rebase-continue.sh:test_must_fail git rebase -i -s funny -Xopt -Xfoo master topic t3510-cherry-pick-sequence.sh:test_expect_code 128 git cherry-pick -s -m $mainline --strategy=recursive -X patience -X ours initial..anotherpick &&

请查看t3510-cherry-pick-sequence.sh,它使用与git merge相同的策略/选项

test_expect_code 128 git cherry-pick -s -m $mainline --strategy=recursive -X patience -X ours initial..anotherpick 

感谢您指出这个事实,即对于为不同的git子命令提供多个“-X”选项,使用不同的语法。 - user001
2
@user001 我已经找到了一个使用多个策略选项的例子:请查看我的编辑后的回答。 - VonC
感谢更新--看起来可能可以使用多个而不会覆盖。你觉得是什么原因导致cherry-pick命令以状态128退出,这似乎表明出现了意外错误(https://dev59.com/PG445IYBdhLWcg3wUoxe#8059956)? - user001
1
@user001 不太确定。我在无效文件描述符的情况下看到过它(https://stackoverflow.com/a/18939111/6309),或者可以避免使用-1的方法:https://dev59.com/o6Pia4cB1Zd3GeqP5-7h#52902804。或者作为一种表示无效值的方式:https://stackoverflow.com/a/42797658/6309。 - VonC

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接