如何在蚂蚁中运行git checkout?

时间:2017-01-09 23:15:39

标签: windows git ant commit git-checkout

我一直在阅读post这个特定日期的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,但这个似乎缺少一些关键的东西。

提前致谢

1 个答案:

答案 0 :(得分:1)

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

pathspec 'de957d59f5ebef20f34155456b8ab46f127dc345 '
                                                  ^ a space

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

为避免处理空间,请考虑使用<loadfile>代替git rev-listoutputproperty的结果保存到Ant属性:

output

上述版本很不错,因为它避免了创建存储<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"通常是件好事。