I am using JGit API ( https://www.eclipse.org/jgit/ ) to access a git repository.
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'
How to filter git diff based on file extensions? using JGit API.
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);
The example uses a PathSuffixFilter
to exclude files ending with .txt
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.