问题
I'm trying a bit with JGIT. It's work very well, but I haven't found out how to show changes on a remote git before makeing a pull. In the terminal I solved my problem with the following steps:
git fetch
git diff --name-status master origin/master
How can I get the remote changes with JGit? Has anyone a idea?
I think the thread How do I do the equivalent of "git diff --name-status" with jgit? can help, but I don't know how to get the remote HEAD.
回答1:
I found out how to get the remote HEAD (FETCH_HEAD). Now my Code is as follows:
git.fetch().call();
Repository repo = git.getRepository();
ObjectId fetchHead = repo.resolve("FETCH_HEAD^{tree}");
ObjectId head = repo.resolve("HEAD^{tree}");
ObjectReader reader = repo.newObjectReader();
CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
oldTreeIter.reset(reader, head);
CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
newTreeIter.reset(reader, fetchHead);
List<DiffEntry> diffs= git.diff().setShowNameAndStatusOnly(true)
.setNewTree(newTreeIter)
.setOldTree(oldTreeIter)
.call();
for(DiffEntry entry : diffs) {
System.out.println(entry.toString());
}
It shows me remote changes like I wanted, but it works not correct. If I create a new File in my working-copy and commit the file (without to push), then the diff show me that the new file is deleted in the FETCH_HEAD. How can I filter this false delete messages?
来源:https://stackoverflow.com/questions/22435714/jgit-show-remote-changes-like-git-diff-name-status-master-origin-master