jgit-基于文件扩展名的git diff [英] jgit - git diff based on file extension

查看:113
本文介绍了jgit-基于文件扩展名的git diff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using JGit API (https://www.eclipse.org/jgit/) to access a git repository.

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

In the git repository, I am storing .txt files and other file formats also. I ran into a requirement where I should get the diff of only .txt files.

基本上,我正在尝试达到

Basically I am trying to achieve the equivalent of

git diff master HEAD -- '*.txt'  

如何根据文件扩展名过滤git diff? /a>使用JGit API.

How to filter git diff based on file extensions? using JGit API.

从这个答案中,(相当于JGit中的git diff )了解如何获得正常的差异.但是我想对此添加文件扩展名限制,但在DiffCommand文档(

From this answer, (Equivalent of git diff in JGit) I understood how to get the normal diff. But I would like to add the file extension restriction to that but I could not see anything in the DiffCommand doc (https://download.eclipse.org/jgit/site/5.2.0.201812061821-r/apidocs/index.html).

有人可以给我一些指点吗?

Could some one please give some pointer?

推荐答案

如果按照

If you use a DiffFormatter as suggested in Equivalent of git diff in JGit, you can specify a tree filter like this:

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

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

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

The example uses a PathSuffixFilter to exclude files ending with .txt.

这篇关于jgit-基于文件扩展名的git diff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆