在构建过程中获取 git 分支名称

Pet*_*Mmm 3 git ant netbeans-7

我想获取当前的 git 分支名称以使用包含分支名称的文件名构建二进制文件。在 Netbeans(7.1) 中使用 ant 可以吗?

小智 5

如果您不想处理 env 变量(如上面的解决方案中所建议的那样)并且如果 git 命令可从您的命令行使用,则另一种解决方案是使用 ANT exec:

<exec executable="git" outputproperty="git.branch"
 failifexecutionfails="false">
 <arg line="rev-parse --abbrev-ref HEAD"/>
</exec>
<echo message="Current branch: ${git.branch}"/> 
Run Code Online (Sandbox Code Playgroud)

(解决方案基本上结合了http://llbit.se/?p=1876How to get the current branch name in Git?