git-commit-id-plugin插件的使用

本文介绍如何通过git-commit-id-plugin插件解决项目依赖包版本追踪难题,生成git.properties文件以快速定位打包分支。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在工作中遇到这样一个问题,项目A是一个老项目,最近又对它进行了一些bug修复操作,但是项目B又在使用项目A中的方法,更棘手的是,不知道项目B使用的项目A是基于哪个分支打下的包,在git上找不到对应的commitId.

解决办法:查看git上代码的历史版本中的修改,比对项目B中使用的项目A的代码,找到他是基于哪个分支或者哪个节点进行的打包,找到对应的commitId,并基于他创建一个新的分支,在idea的终端输入命令:git  checkout   commitId -b 新分支名

这样每次让我们去比对版本是很麻烦的事情,介绍一个插件 git-commit-id,在打包完,我们就可以在classes目录下找到一个 git.properties,这样我们就可以根据他找到是基于哪个节点打的包

   <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>2.2.5</version>
                <executions>
                    <execution>
                        <id>get-the-git-infos</id>
                        <!-- 默认绑定阶段initialize -->
                        <phase>initialize</phase>
                        <goals>
                            <!-- 目标:revision -->
                            <goal>revision</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- 定义插件中所有时间格式,默认值:yyyy-MM-dd’T’HH:mm:ssZ -->
                    <dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
                    <!-- 生成git属性文件,默认false:不生成 -->
                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
                    <!-- 生成git属性文件路径及文件名,默认${project.build.outputDirectory}/git.properties -->
                    <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
                    <!-- 生成git属性文件格式,默认值properties -->
                    <format>json</format>
                    <!-- git.properties包含的内容-->
                    <includeOnlyProperties>
                        <!--  所在分支                      -->
                        <includeOnlyProperty>^git.branch$</includeOnlyProperty>
                        <includeOnlyProperty>^git.build.time$</includeOnlyProperty>
                        <includeOnlyProperty>^git.commit.time$</includeOnlyProperty>
                        <!--  commit-id  -->
                        <includeOnlyProperty>^git.commit.id.full$</includeOnlyProperty>
                        <includeOnlyProperty>^git.build.version$</includeOnlyProperty>
                        <!-- 所属分分支名 -->
                        <includeOnlyProperty>^git.closest.tag.name$</includeOnlyProperty>
                    </includeOnlyProperties>
                </configuration>
            </plugin>

当我们打包后,在target->class目录下就会出现 git.properties文件

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值