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?
The git diff command displays the differences between files in two commits or between a commit and your current repository. You can see what text has been added to, removed from, and changed in a file. By default, the git diff command displays any uncommitted changes to your repository.
Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.
I get that R probably stands for "Rename". git rename.
In answer to the original question, git diff isn't showing anything because you have a brand new directory, with a newly added file, but there are zero changes in the file for git diff to show. git status is showing that you added a new file, but git diff is for showing changes within files.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With