【问题标题】:How to run git checkout in ant?如何在蚂蚁中运行 git checkout?
【发布时间】:2017-05-24 08:06:42
【问题描述】:

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

提前致谢

【问题讨论】:

  • 您确定这是正确的 sha1 密钥并且您当前的工作目录在您认为的 git 存储库中吗?可以手动执行命令吗?

标签: windows git ant commit git-checkout


【解决方案1】:

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

pathspec 'de957d59f5ebef20f34155456b8ab46f127dc345 '
                                                  ^ a space

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

为避免处理空间,请考虑使用outputproperty 而不是outputgit 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结果的文件。它还会删除对&lt;loadfile&gt; 的调用。

顺便说一句,您可能想要使用failonerror="true" 而不是failifexecutionfails="true"failifexecutionfails 默认为true,所以可以省略。但是,failonerror 默认为 false。将failonerror="true" 添加到&lt;exec&gt; 通常是一件好事。

【讨论】:

  • 嗨,乍得,这绝对是我还不能投票的答案,但你猜对了。我发现了困难的方法,但你是对的,exec 的输出确实在文件末尾插入了一个新行,因此导致了问题。当我手动将确切的 SHA ID 复制粘贴到 arg line 中时,我就明白了。另外,感谢您的建议,我不知道failonerrorfailonerror 是这种情况。仅供参考,我无法 c
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-22
  • 2010-10-16
  • 1970-01-01
  • 1970-01-01
  • 2017-04-14
相关资源
最近更新 更多