[英]Find all commits that changed a given directory from Java
I write a Java program, and I use jgit.我写了一个Java的程序,我用的是jgit。 In this Java program, I want to list all commits of some git repository g
that changed at least one file in a directory x
.在这个 Java 程序中,我想列出某个 git 存储库g
的所有提交,这些提交至少更改了目录x
中的一个文件。
I do not want to solve the problem "on command line", but within Java.我不想“在命令行上”解决问题,而是在 Java 内解决。
In the high-level API of JGit you can use Git.log() with "addPath" to get a simple list of related commits.在 JGit 的高级 API 中,您可以使用Git.log()和“addPath”来获取相关提交的简单列表。
logs = git.log()
.addPath("pom.xml")
.call();
See this snippet in the jgit-cookbook for a ready-to-run example.请参阅jgit-cookbook中的此片段以获取可立即运行的示例。
In general the methods on the entry-class Git provide similar functionality to the regular git commands.通常,入门级Git上的方法提供与常规 git 命令类似的功能。
For the low-level API which provides much more fine-grained control/results, you can use Git.diff() with "newTree" and "oldTree" and a "pathFilter".对于提供更细粒度控制/结果的低级 API,您可以将Git.diff()与“newTree”和“oldTree”以及“pathFilter”一起使用。 The trees are constructed via RevWalk and CanonicalTreeParser这些树是通过RevWalk和CanonicalTreeParser构建的
There is a related snippet for this approach in the jgit-cookbook at ShowFileDiff.java在ShowFileDiff.java的jgit-cookbook中有此方法的相关片段
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.