我正在使用 JGit API ( https://www.eclipse.org/jgit/ ) 访问 git 存储库。
在 git 存储库中,我还存储 .txt 文件和其他文件格式。我遇到了一个要求,我应该只获取 .txt 文件的差异。
基本上我正在努力实现相当于
git diff master HEAD -- '*.txt'
How to filter git diff based on file extensions?使用 JGit API。
从这个答案,(Equivalent of git diff in JGit)我明白了如何获得正常的差异。但我想向其添加文件扩展名限制,但我在 DiffCommand
文档(https://download.eclipse.org/jgit/site/5.2.0.201812061821-r/apidocs/index.html)中看不到任何内容。
谁能给点指点吗?
最佳答案
如果您按照 Equivalent of git diff in JGit 中的建议使用 DiffFormatter
,您可以像这样指定一个树过滤器:
TreeFilter treeFilter = PathSuffixFilter.create(".txt")
DiffFormatter diffFormatter = ...
diffFormatter.setPathFilter(treeFilter);
该示例使用 PathSuffixFilter
来排除以 .txt
结尾的文件。
关于java - jgit - 基于文件扩展名的 git diff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54008247/