如何从 JGit 中的 diff 目标中排除多个文件扩展名

How to exclude multiple file extension from diff target in JGit

我找到了一种从 JGit diff 中排除指定文件扩展名的方法:

val excludePath = PathSuffixFilter.create(".designer.cs").negate()
val df = new DiffFormatter(DisabledOutputStream.INSTANCE)
df.setPathFilter(excludePath);

多个文件扩展名怎么办?

有一个 OrTreeFilter 和一个 AndTreeFilter 可以组合多个 TreeFilter

要排除多个文件结尾,请将单路径过滤器与 AndTreeFilter 组合起来,并使用它来配置 diff 格式化程序:

val fooFilter = PathSuffixFilter.create(".foo").negate()
val barFilter = PathSuffixFilter.create(".bar").negate()
val treeFilter = AndTreeFilter.create(fooFilter, barFilter);
...
diffFormatter.setPathFilter(treeFilter);