Looping over commits for a file with jGit

Posted by Andy Jarrett on Stack Overflow See other posts from Stack Overflow or by Andy Jarrett
Published on 2011-01-24T00:06:27Z Indexed on 2012/09/27 15:37 UTC
Read the original article Hit count: 207

Filed under:
|

I've managed to get to grips with the basics of jGit file in terms of connecting to a repos and adding, commiting, and even looping of the commit messages for the files.

File gitDir = new File("/Users/myname/Sites/helloworld/.git");

RepositoryBuilder builder = new RepositoryBuilder();
Repository repository;
repository = builder.setGitDir(gitDir).readEnvironment()
        .findGitDir().build();

Git git = new Git(repository);
RevWalk walk = new RevWalk(repository);
RevCommit commit = null;

// Add all files
// AddCommand add = git.add();
// add.addFilepattern(".").call();

// Commit them
// CommitCommand commit = git.commit();
// commit.setMessage("Commiting from java").call();

Iterable<RevCommit> logs = git.log().call();
Iterator<RevCommit> i = logs.iterator();

while (i.hasNext()) {
    commit = walk.parseCommit( i.next() );
    System.out.println( commit.getFullMessage() );

}

What I want to do next is be able to get all the commit message for a single file and then be able revert the single file back to a specific reference/point in time.

© Stack Overflow or respective owner

Related posts about java

Related posts about jgit