读取最后一次提交的git和提交编号 [英] Read last commit of the git and commit number

查看:103
本文介绍了读取最后一次提交的git和提交编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Git源代码的maven项目中,每当我用maven编译一个构建,读取最后一次提交的git和提交编号时,是否可能?

我希望使用该提交编号来查找最后一次提交。 解决方案

这是假设您想要读取该信息,然后将其存储在属性文件中。
基于 https://github.com / ktoso / maven-git-commit-id-plugin#using-the-plugin

pom.xml:

 <?xml version =1.0encoding =UTF-8?> 
< project xmlns =http://maven.apache.org/POM/4.0.0
xsi:schemaLocation =http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd
xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance>
<! - 剪辑其他内容... - >
< build>
<! - GIT COMMIT ID插件配置 - >
<资源>
< resource>
<目录> src / main / resources< /目录>
<过滤>真实< /过滤>
<包括>
< include> ** / *。properties< / include>
< / includes>
< / resource>
< /资源>

< plugins>
< plugin>
< groupId> pl.project13.maven< / groupId>
< artifactId> git-commit-id-plugin< / artifactId>
< version> 2.2.1< / version>
<执行次数>
<执行>
<目标>
< goal>修订< / goal>
< /目标>
< /执行>
< /执行次数>

<配置>
< commitIdGenerationMode> flat< / commitIdGenerationMode>
< gitDescribe>
< skip> true< / skip>
< / gitDescribe>
< / configuration>

< / plugin>
<! - GIT COMMIT ID插件配置结束 - >

<! - 其他插件 - >
< / plugins>
< / build>
< / project>

/ src / main / resources中的git.properties:

  git.commit.id = $ {git.commit.id} 


In maven project with Git source code, Is it possible whenever I am compiling a build with maven, to read the last commit of the git and commit number.

I want to use that commit number to be able to find the last commit.

解决方案

This is assuming you want to read that information, then store it in a property file. Based on https://github.com/ktoso/maven-git-commit-id-plugin#using-the-plugin:

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <!-- snip other stuff... -->
    <build>
        <!-- GIT COMMIT ID PLUGIN CONFIGURATION -->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>revision</goal>
                         </goals>
                    </execution>
                </executions>

                <configuration>
                    <commitIdGenerationMode>flat</commitIdGenerationMode>
                    <gitDescribe>
                        <skip>true</skip>
                    </gitDescribe>
                </configuration>

            </plugin>
            <!-- END OF GIT COMMIT ID PLUGIN CONFIGURATION -->

            <!-- other plugins -->
        </plugins>
    </build>
</project>

git.properties in /src/main/resources:

git.commit.id=${git.commit.id}

这篇关于读取最后一次提交的git和提交编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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