我一直在阅读这个 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 clone
和 git log
,但这个似乎是缺少一些重要的东西。
提前致谢
最佳答案
在错误消息中,我注意到结束引号前有一个空格:
pathspec 'de957d59f5ebef20f34155456b8ab46f127dc345 '
^ a space
我相信 output
的 <exec>
属性会在输出文件的末尾插入一个换行符。 <loadfile>
稍后将换行符转换为空格。
为避免处理空格,考虑使用 git rev-list
而不是 outputproperty
将 output
的结果保存到 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/