简体   繁体   English

查找从 Java 更改给定目录的所有提交

[英]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这些树是通过RevWalkCanonicalTreeParser构建的

There is a related snippet for this approach in the jgit-cookbook at ShowFileDiff.javaShowFileDiff.javajgit-cookbook中有此方法的相关片段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何比较给定目录 java 中的所有文件名? - How to compare all file names from a given directory java? java程序从给定的字符串中查找所有词典单词 - java program to find all dictionary words from a given string Java - 将函数应用于给定目录中的所有文件 - Java - Apply Function to All Files in Given Directory 使用Java API从GitHub获取所有提交 - Get all commits from GitHub using Java API 如何从给定模式的目录和子目录中获取所有文件 - How to get all files from directory and sub directory with a given pattern Java:从给定元素开始,在2D数组中查找具有相同值的所有相邻元素 - Java: find in 2d array all adjacent elements with the same value, starting from a given element 在 java 中通过 hashmap 从数组中查找所有元素对,其总和等于给定数 - Find all pairs of elements from an array whose sum is equal to given number by hashmap in java 从给定查询中查找所有可能的单词 - find all possible words from a given query 如何读取给定目录中的所有txt文件以查找字符串? Java的 - How to read all txt files in a given directory to look for a string? Java javac选项递归编译给定目录下的所有java文件 - javac option to compile all java files under a given directory recursively
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM