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.