Git-git bisect 寻找maven中bug的实践

211 阅读1分钟

github.com/zhengquan45… 这个仓库里给出了一个Maven的bug示例。请使用git bisect方法,在 github.com/apache/mave… 仓库中找到引入bug的那个commit的id

ps:当然github太慢你可以把它导到码云中git clone

1、git clone https://github.com/apache/maven.git
2、cd ./maven && git checkout maven-3.6.1
3、mvn clean package -DskipTests -Drat.skip=true
4、unzip apache-maven/target/apache-maven-3.6.1-bin.zip -d .
5、apache-maven-3.6.1/bin/mvn -f ~/project/maven-issue-reproduction/pom.xml compile
6、git bisect bad (告诉git这个commit有错)
7、重复步骤2 编译3.6.0  && git bisect good (这是git会告诉你需要多少步找到第一次引入错误的commit)

以上方式如果你一个一个commit checkout 打包编译测试必然劳心劳力

git bisect 提供一种能自动化的命令 所以我们需要用sh脚本提炼上面的步骤(如果路径不对请自改)

vi run.sh

#!/bin/sh

VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)

rm -rf apache-maven-* &&\
mvn clean package -DskipTests -Drat.skip=true &&\
unzip apache-maven/target/apache-maven-$VERSION-bin.zip -d . &&\
apache-maven-$VERSION/bin/mvn -f ~/project/maven-issue-reproduction/pom.xml compile
8、运行git bisect run ./run.sh 稍等一幅幅就找到啦!