Reputation: 59
even it is not recommended, I use for specific approach a:
git commit -m 'xxxx' file 1 file2
Where both files, that are indexed and changed will be part of the commit. But not e.g. file3 and file4 that are changed too - but not named in the commit.
Question: How can I do this using JGit! Even Eclipse offers this - but I did not find any approach to to this using JGit (porcelain).
Upvotes: 5
Views: 1508
Reputation: 20985
Without having tried myself, there is a setOnly
method on CommitCommand
. According to the documentation you should be able to call
git.commit().setOnly("file1").setOnly("file2").setMessage("...").call();
and the command would add file1
and file2
to a temporary index and then commit in one go.
If that doesn't work you can still use the AddCommand
to add individual files to the index and then commit:
git.add().setFilepattern("file1").addFilepattern("file2").call();
git.commit().setMessage("...").call();
If files were already added, you can reset the index before adding files like so:
git.reset().setMode(ResetType.MIXED).call();
Upvotes: 5