我正在使用JGit API(https://www.eclipse.org/jgit/)来访问git存储库.
在git存储库中,我也存储.txt文件和其他文件格式.我遇到了一个要求,我应该只得到.txt文件的差异.
基本上我试图达到相当于
git diff master HEAD -- '*.txt'
Run Code Online (Sandbox Code Playgroud)
如何根据文件扩展名过滤git diff?使用JGit API.
从这个答案,(相当于JGit中的git diff),我理解了如何获得正常的差异.但我想添加文件扩展名限制,但我在DiffCommand文档中看不到任何内容(https://download.eclipse.org/jgit/site/5.2.0.201812061821-r/apidocs/index.html).
有人可以给一些指针吗?
如果您按照 JGit 中的 git diff 等效项中的DiffFormatter建议使用 a ,您可以指定一个树过滤器,如下所示:
TreeFilter treeFilter = PathSuffixFilter.create(".txt")
DiffFormatter diffFormatter = ...
diffFormatter.setPathFilter(treeFilter);
Run Code Online (Sandbox Code Playgroud)
该示例使用 aPathSuffixFilter来排除以.txt.
| 归档时间: |
|
| 查看次数: |
177 次 |
| 最近记录: |