Git关键字扩展或替代 [英] Git keyword-expansion or alternative

查看:174
本文介绍了Git关键字扩展或替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读了关于此主题的一些帖子之后,我意识到有很多缺点反对使用关键字替换。然而,我需要一种方法来解决以下问题,并希望有人可能有一个关于如何解决这个问题的想法(无论是否使用关键字替换):

我有一个主要的应用程序,我使用git作为VCS。这个主应用程序的某些部分(某些XML文件)正在被我使用git(单独的repo)的实用程序使用。



现在,main应用程序和实用程序具有不同的发布周期,并且每当我发布新版本的实用程序时,我都会复制主应用程序中最新的一组XML文件。
在该实用程序中,这组XML文件在git中是非版本化的内容,所以它甚至不会检入到回购站中。



截至目前,每当我看这个实用程序的不同版本(由git管理并且标记了发行版)时,我无法知道包含的XML文件所指的是哪个版本(更好:提交哈希)。这种方法有什么问题吗?还是这种方式?如果是的话,我如何将最新的commit-SHA加入到我的XML文件中? (我读过$ Id:$不会接受commit-SHA,但是会有一些blob-SHA?)

解决方案

好吧,根据你的输入,这就是我所做的:
$ b


  1. 在我的XML文件中插入占位符:<! - @ GIT_VERSION @ - >

  2. 蚂蚁拿起git版本信息,注意这是Windows:

  3. 让ant将这些信息插入到我的XML文件中,同时复制它们。

代码:

 < target name =getGitDetails> 
< exec executable =cmdoutputproperty =git.revision>
< arg value =/ c/>
< arg value =git.cmd --git-dir =<回购路径>描述--long --dirty --always/>
< / exec>
< exec executable =cmdoutputproperty =git.currentBranchRef>
< arg value =/ c/>
< arg value =git.cmd --git-dir =<回购路径>描述 - 所有/>
< / exec>
< / target>

< target name =builddepends =getGitDetails>
< copy todir =< dest-dir>>
< filterset>
< filter token =GIT_VERSIONvalue =$ {git.currentBranchRef} $ {git.revision}/>
< / filterset>
< / copy>
< / target>

感谢您的帮助!

请参阅还有:




Having read some postings here about this topic, I realize that there are quite some cons that speak against using keyword-substitution. Nevertheless, I need a way to solve following problem and hope that somebody might have an idea on how to solve this with git (whether or not with keyword-substitution):

I have a main application for which I use git as VCS. Parts of this main application (a certain set of XML-Files) are being used by a utility for which I also use git (separate repo).

Now, the main app and the utility have different release cycles, and whenever I release a new version of the utility, I copy over the most current set of XML-Files from the main application. Within the utility, this set of XML-Files is non-versioned content in git, so it's not even checked in to the repo.

As of now, whenever I look at different releases of this utility (which is managed by git and has tagged releases) I have no way of knowing which "version" (better: commit hash) the set of contained XML-Files is referring to.

So I was thinking: if I can have the latest commit SHA within those XML-Files (as a comment), I'd always know to which set of XML-Files a certain version of my utility refers to. Is there anything wrong in this approach or is this the way to go? If yes, how do I get the latest commit-SHA into my XML-Files? (I read that $Id:$ won't take the commit-SHA, but some "blob"-SHA?)

解决方案

Ok guys, based on your input, this is what i did:

  1. Insert placeholders in my XML-Files: <!-- @GIT_VERSION@ -->
  2. Have ant pick up git version information, note that this is Windows:
  3. Have ant insert this info into my XML-Files while copying them over.

Code:

<target name="getGitDetails">
    <exec executable="cmd" outputproperty="git.revision">
         <arg value="/c" />
         <arg value="git.cmd --git-dir=<path-to-repo> describe --long --dirty --always" />
    </exec>
     <exec executable="cmd" outputproperty="git.currentBranchRef">
         <arg value="/c" />
         <arg value="git.cmd --git-dir=<path-to-repo> describe --all" />
     </exec>
 </target>

 <target name="build" depends="getGitDetails">
     <copy todir="<dest-dir>">  
         <filterset>
             <filter token="GIT_VERSION" value="${git.currentBranchRef} ${git.revision}" />
         </filterset>
     </copy>
 </target>

Thanks for your help!

See also:

How to lookup the latest git commit hash from an ant build script

Deriving application build version from `git describe` - how to get a relatively straightforward string?

这篇关于Git关键字扩展或替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆