0

I'm very new at JGit and I'm searching a implementation of this Git command:

git show --stat < sha >

(Which shows me all affected files within the commit.)

I have the RevCommit, but how can I get the information which is displayed by git show?

Biffen
  • 6,249
  • 6
  • 28
  • 36
szumbe
  • 1
  • 1
  • Do you want to list _all_ files that make up a commit or the _changed_ files (i.e. file that differ from the parent commit)? – Rüdiger Herrmann Oct 31 '16 at 10:19
  • thanks rüdiger for your answer, i want the changed files.. – szumbe Oct 31 '16 at 11:21
  • Then you should rewrite your question to reflect that. `git show` lists the _contents_ of a git object (commit/blob/tree). To list _changes_ use `git diff`. See here for how to achieve that with JGit: http://stackoverflow.com/questions/27361538/how-to-show-changes-between-commits-with-jgit – Rüdiger Herrmann Oct 31 '16 at 11:26

1 Answers1

0

To list the files that make up a commit, you need to use a TreeWalk. A TreeWalk can be initialized with the object id (SHA-1) of a tree and then use to traverse over its entries.

For example:

TreeWalk treeWalk = new TreeWalk( repository );
treeWalk.setRecursive( true );
treeWalk.reset( commit.getId() );
while( treeWalk.next() ) {
  String path = treeWalk.getPathString();
  String blobId = treeWalk.getObjectId( 0 );
  // ...
}

getPathString() returns the (repository-relative) path to the current entry.

getObjectId() expects an index that identifies the tree iterator of which the object id should be obtained. Here, the first and only tree iterator is specified that what was implicitly created by reset() for the tree of the given commit.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79