git项目比对_gitDiffTool 是一个Git代码对比工具,可以对Git项目的两个提交进行对比...

gitDiffTool是一款用于比较Git项目两个提交的工具,它能生成HTML格式的差异报告,显示在output/目录下。用户可以在单一HTML页面上看到修改的文件列表和具体的差异内容。
摘要由CSDN通过智能技术生成

gitDiffTool

gitDiffTool is a tool to compare two commits of a gitProject and generate the diff into html(generate in output/ dir of current dir). You can read the diff in one html page, the list of modified files on one side and the specifics diff-content on the other.

usage

Usage: gitDiffTool.py [OPTIONS] [params]

-d [sCommit] dCommit : diff two commit(if given one diff with current commit), output the result using html

-h|--help : print this usage

-v|--version : print the version

example

gitDiffTool.py -d 79809324 341324 # compare tow commit

gitDiffTool.py -d 787234 # compare current branch with given commit

gitDiffTool.py -d develop # compare current branch with given branch's name

中文简介 chinese

gitDiffTool 是一个Git代码对比工具,可以对Git项目的两个提交进行对比,对比结果将生成一份html报告(结果生成在当前output/目录下)。 你可以在生成的结果页中查看两次提交间代码的diff,结果页仅为单个html页面,

以下是一个简单的示例程序,可以获取同一个 Java 类不同代码提交变更的方法: ```java import org.eclipse.jgit.api.Git; import org.eclipse.jgit.diff.DiffEntry; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.treewalk.filter.PathFilter; import java.io.IOException; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; public class JavaCodeChanges { public static void main(String[] args) throws IOException { String repoDir = "/path/to/your/repo"; // Git 仓库的本地路径 String filePath = "src/main/java/YourClass.java"; // Java 类文件的路径 List<String> methods = new ArrayList<>(); // 保存方法名的列表 try (Git git = Git.open(Paths.get(repoDir))) { Iterable<RevCommit> commits = git.log().addPath(filePath).call(); RevCommit prevCommit = null; for (RevCommit commit : commits) { if (prevCommit != null) { RevWalk walk = new RevWalk(git.getRepository()); List<DiffEntry> diffs = git.diff() .setOldTree(walk.parseTree(prevCommit)) .setNewTree(walk.parseTree(commit)) .setPathFilter(PathFilter.create(filePath)) .call(); for (DiffEntry diff : diffs) { String[] lines = git.show().setPath(diff.getNewPath()).call().split("\n"); for (String line : lines) { if (line.matches("^\\s*public.*\\(.*\\)\\s*\\{\\s*$")) { String method = line.replaceFirst("^\\s*public\\s*", "") .replaceFirst("\\(.*\\)\\s*\\{\\s*$", ""); if (!methods.contains(method)) { methods.add(method); } } } } walk.dispose(); } prevCommit = commit; } } System.out.println("Methods changed: " + methods); } } ``` 这个程序使用 JGit 库来访问 Git 仓库,并使用 `git diff` 命令来比较两个提交之间 Java 类文件的差异。它会输出所有变更过的方法名。你需要替换 `repoDir` 和 `filePath` 变量为你自己的值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值