jgit - 基于文件扩展名的 git diff

2024-04-25

我正在使用 JGit API (https://www.eclipse.org/jgit/ https://www.eclipse.org/jgit/) 访问 git 存储库。

在 git 存储库中,我还存储 .txt 文件和其他文件格式。我遇到了一个要求,我应该只获取 .txt 文件的差异。

基本上我想达到相当于

git diff master HEAD -- '*.txt'  

如何根据文件扩展名过滤 git diff? https://stackoverflow.com/questions/8554776/how-to-filter-git-diff-based-on-file-extensions使用 JGit API。

从这个答案来看,(相当于 JGit 中的 git diff https://stackoverflow.com/questions/31325613/equivalent-of-git-diff-in-jgit)我明白了如何获得正常的差异。但我想添加文件扩展名限制,但我在其中看不到任何内容DiffCommand doc (https://download.eclipse.org/jgit/site/5.2.0.201812061821-r/apidocs/index.html https://download.eclipse.org/jgit/site/5.2.0.201812061821-r/apidocs/index.html).

有人可以指点一下吗?


如果您使用DiffFormatter如建议的相当于 JGit 中的 git diff https://stackoverflow.com/questions/31325613/equivalent-of-git-diff-in-jgit,您可以像这样指定树过滤器:

TreeFilter treeFilter = PathSuffixFilter.create(".txt")

DiffFormatter diffFormatter = ...
diffFormatter.setPathFilter(treeFilter);

该示例使用PathSuffixFilter排除以以下结尾的文件.txt.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

jgit - 基于文件扩展名的 git diff 的相关文章

随机推荐