简体   繁体   English

如何在蚂蚁中运行git checkout?

[英]How to run git checkout in ant?

I have been reading this post to git checkout by a specific date. 我一直在特定日期阅读这篇帖子给git checkout。 I have been able to obtain the revision commit SHA code to the specific commit that I am targeting for the checkout, but when I am trying to actually run the git checkout command line I got the error: 我已经能够将修订提交SHA代码获取到我为结帐定位的特定提交,但是当我尝试实际运行git checkout命令行时,我收到了错误:

error: pathspec 'de957d59f5ebef20f34155456b8ab46f127dc345 ' did not match any file(s) known to git. 错误:pathspec'de957d59f5ebef20f34155456b8ab46f127dc345'与git已知的任何文件都不匹配。

Not sure what that means. 不确定那是什么意思。 I am running this command from ant 1.94 on my windows 7 machine 我在Windows 7机器上从ant 1.94运行此命令

The ant command script looks as follow: 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>

Where the first execution actually retrieve the SHA (de957d59f5ebef20f34155456b8ab46f127dc345) code successfully, but when trying to use that for the second execution tasks command arguments, it throughs the above error. 第一次执行实际上成功检索了SHA(de957d59f5ebef20f34155456b8ab46f127dc345)代码,但是当尝试将其用于第二个执行任务命令参数时,它会通过上述错误。

Any ideas/recommendations on what I am missing here. 关于我在这里缺少什么的任何想法/建议。 Like I mentioned, I do have several task command lines that look like this and are used to perform other tasks, like git clone and git log , but this one seems to be missing something crucial. 就像我提到的,我确实有几个任务命令行看起来像这样,并用于执行其他任务,如git clonegit log ,但这个似乎缺少一些关键的东西。

Thanks in advance 提前致谢

In the error message, I noticed a space before the end quote: 在错误消息中,我注意到结束引用前的空格:

pathspec 'de957d59f5ebef20f34155456b8ab46f127dc345 '
                                                  ^ a space

I believe the output attribute of <exec> inserts a newline at the end of the output file. 我相信<exec>output属性在输出文件的末尾插入换行符。 <loadfile> later converts the newline into a space. <loadfile>稍后将换行符转换为空格。

To avoid dealing with the space, consider saving the results of git rev-list to an Ant property by using outputproperty instead of output : 为避免处理空间,请考虑使用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>

The above version is nice because it avoids having to create a file that stores the results of git rev-list . 上面的版本很好,因为它避免了必须创建一个存储git rev-list结果的文件。 It also removes a call to <loadfile> . 它还会删除对<loadfile>的调用。

By the way, you may want to use failonerror="true" instead of failifexecutionfails="true" . 顺便说一句,你可能想使用failonerror="true"而不是failifexecutionfails="true" failifexecutionfails is true by default, so that can be omitted. failifexecutionfails默认为true ,因此可以省略。 failonerror , however, is false by default. 但是, failonerror默认为false Adding failonerror="true" to <exec> is usually a good thing to do. failonerror="true"添加到<exec>通常是一件好事。

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

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