windows - 如何在 ant 中运行 git checkout?

标签 windows git ant commit git-checkout

我一直在阅读这个 post 到特定日期的 git checkout。我已经能够获得针对我针对 checkout 的特定提交的修订提交 SHA 代码,但是当我尝试实际运行 git checkout 命令行时,我收到了错误:

error: pathspec 'de957d59f5ebef20f34155456b8ab46f127dc345 ' did not match any file(s) known to 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

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

为避免处理空格,考虑使用 git rev-list 而不是 outputpropertyoutput 的结果保存到 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> 通常是一件好事。

关于windows - 如何在 ant 中运行 git checkout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41558587/

相关文章:

在 Mac 中安装后 git gui 不工作(例如 Mountain Lion)

Javadoc 在一个包中只有一个类使用 Ant

c - 是否可以检查您是否正在使用 Microsoft C 编译器构建 64 位?

c# - 如何找到我的Winform应用程序和Outlook插件的最低系统要求

git - 编辑过去的提交消息

git - 根据文件夹设置git凭据

c++ - 如何以编程方式重启?

C++:从哪里获得不使用垂直同步的帧速率限制器?

java - Ant build.xml 文件无法使用 fileset 元素中的属性

java - 最终静态字符串编译问题。任何建议如何避免?