繁体   English   中英

如何在蚂蚁中运行git checkout?

[英]How to run git checkout in ant?

我一直在特定日期阅读这篇帖子给git checkout。 我已经能够将修订提交SHA代码获取到我为结帐定位的特定提交,但是当我尝试实际运行git checkout命令行时,我收到了错误:

错误:pathspec'de957d59f5ebef20f34155456b8ab46f127dc345'与git已知的任何文件都不匹配。

不确定那是什么意思。 我在Windows 7机器上从ant 1.94运行此命令

ant命令脚本如下所示:

 <target name="git.revlist" description="Revision list of repo for a particular timeframe" >
    <exec executable="git" dir="${run.repo.dir}" failifexecutionfails="true" output="${output_commit_sha_file}" >
        <arg line="rev-list -n 1 --before=${snapshot_before_date} ${repo_branch}"/>
    </exec>
    <loadfile property="output_commit_sha" srcfile="${output_commit_sha_file}"  />
    <exec executable="git" dir="${run.repo.dir}" failifexecutionfails="true" >
        <arg line="checkout ${output_commit_sha}"/>
    </exec> 
 </target>

第一次执行实际上成功检索了SHA(de957d59f5ebef20f34155456b8ab46f127dc345)代码,但是当尝试将其用于第二个执行任务命令参数时,它会通过上述错误。

关于我在这里缺少什么的任何想法/建议。 就像我提到的,我确实有几个任务命令行看起来像这样,并用于执行其他任务,如git clonegit log ,但这个似乎缺少一些关键的东西。

提前致谢

在错误消息中,我注意到结束引用前的空格:

pathspec 'de957d59f5ebef20f34155456b8ab46f127dc345 '
                                                  ^ a space

我相信<exec>output属性在输出文件的末尾插入换行符。 <loadfile>稍后将换行符转换为空格。

为避免处理空间,请考虑使用outputproperty而不是output来将git rev-list的结果保存到Ant属性:

<exec executable="git" dir="${run.repo.dir}" outputproperty="output_commit_sha">
    <arg line="rev-list -n 1 --before=${snapshot_before_date} ${repo_branch}"/>
</exec>
<exec executable="git" dir="${run.repo.dir}">
    <arg line="checkout ${output_commit_sha}"/>
</exec>

上面的版本很好,因为它避免了必须创建一个存储git rev-list结果的文件。 它还会删除对<loadfile>的调用。

顺便说一句,你可能想使用failonerror="true"而不是failifexecutionfails="true" failifexecutionfails默认为true ,因此可以省略。 但是, failonerror默认为false failonerror="true"添加到<exec>通常是一件好事。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM