我正在尝试一次为多个提交ID实现Git精选。但是它失败了,或者这不是应该使用的方式。
我正在尝试从此处使用bash命令:https://stackoverflow.com/a/2553705/9614476
#!/bin/bash
if [ -z $1 ]; then
echo "Equivalent to running git-cherry-pick on each of the commits in the range specified.";
echo "";
echo "Usage: $0 start^..end";
echo "";
exit 1;
fi
git rev-list --reverse --topo-order $1 | while read rev
do
git cherry-pick $rev || break
done
我像这样为蚂蚁创建了一个目标:
<target name="git_multi_cherry_pick">
<echo message="START: MultiMerge"/>
<exec executable="C:\Program Files\Git\bin\bash.exe" osfamily="windows" failonerror="true">
<arg value="${gitMultiCherryPick}"/>
<arg value="${gitCommitIds}"/>
</exec>
<exec executable="/bin/bash" osfamily="unix" failonerror="true">
<arg value="${gitMultiCherryPick}"/>
<arg value="${gitCommitIds}"/>
</exec>
</target>
而且我正在使用Java中的AntExecutor
来调用上述目标。AntExecutor code can be found here - https://github.com/asciidoctor/asciidoctor-ant/blob/master/src/test/java/org/asciidoctor/ant/AntExecutor.java
Map<String, String> propertiesMap = new HashMap<>();
propertiesMap.put("gitMultiCherryPick", "git-multi-cherry-pick.sh");
propertiesMap.put("gitCommitIds", "204a3e81712000d09a2794cc4ef1d090c4280f4e,9c5242d6a15b14032e9fc1f408be3c91026b1e1f");
List<String> sf_build = AntExecutor.executeAntTask("FullPath \\resources\\build\\build.xml",
"git_multi_cherry_pick", propertiesMap);
但是失败并显示此错误:
The ' characters around the executable and arguments are
not part of the command., 204a3e81712000d09a2794cc4ef1d090c4280f4e,9c5242d6a15b14032e9fc1f408be3c91026b1e1f, git-multi-cherry-pick.sh, fatal: ambiguous argument '204a3e81712000d09a2794cc4ef1d090c4280f4e,9c5242d6a15b14032e9fc1f408be3c91026b1e1f':
我认为这不是我们传递commitIds的方式。有人使用过上述bash脚本吗?
我认为您实际上是在寻找git rebase
,而不是git cherry-pick
(两者都可以执行相同的工作)。最新的Git版本中的git cherry-pick
甚至可以直接处理多个提交,而无需外部循环。
要解决您的特定问题:在命令行上指定多个提交引用时,这些需要由您的shell IFS(输入字段分隔符)分隔,通常是空格,很少是逗号(,
)。
可能的解决方案:
204a3e81712000d09a2794cc4ef1d090c4280f4e 9c5242d6a15b14032e9fc1f408be3c91026b1e1f
(请注意脚本中的引用)IFS
设置为','
git cherry-pick
已经可以一次选择多个提交(请参见documentation)。您仍然需要将映射中的值从逗号固定为空白,但是可以简化Shell脚本:
#!/bin/sh
if [ -z "$1" ]; then
echo "Equivalent to running git-cherry-pick on each of the commits in the range specified.";
echo "";
echo "Usage: $0 start^..end";
echo "";
exit 1;
fi
# do not quote parameter, we need its whitespace as whitespace
git cherry-pick $1
(而且您不需要bash
,sh
完全可以满足这样的脚本)