I would like to know how I can retrieve the list of changed files after a pull request.
I'm using this to get all the merged commits, but I want to know all the changed files.
Git git = new Git(localRepo);
PullCommand pullCmd = git.pull();
PullResult pullResult = pullCmd.call();
MergeResult mergeResult = pullResult.getMergeResult();
ObjectId[] mergedCommits = mergeResult.getMergedCommits();
for (ObjectId mergedCommit : mergedCommits) {
// And now?
}
Building on the previous comments/questions:
Get the current head before you pull:
ObjectId oldHead = repository.resolve("HEAD^{tree}");
And after the pull again:
ObjectId head = repository.resolve("HEAD^{tree}");
Then you should be able to run the diff the same way as in How do I do the equivalent of "git diff --name-status" with jgit? :
ObjectReader reader = repository.newObjectReader();
CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
oldTreeIter.reset(reader, oldHead);
CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
newTreeIter.reset(reader, head);
List<DiffEntry> diffs= git.diff()
.setNewTree(newTreeIter)
.setOldTree(oldTreeIter)
.call();
$git diff-tree --no-renames --no-commit-id --name-only -r
My Approach that works for me:
1. Cat all the hashes into a file (Say tempfile1)
2. xargs -n1 git diff-tree --no-renames --no-commit-id --name-only -r < tempfile1 >> tempfile2
3. sort tempfile2 | uniq >> final (To remove duplicate entries)
final file will have all the changed files
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.