Last active
March 27, 2017 13:19
-
-
Save noorulhaq/6991e63bfd1f10c89a4c7ee98a43e757 to your computer and use it in GitHub Desktop.
Git commit log gist, that demostrate how you can list commits from git repsoitory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package crossover; | |
import org.eclipse.jgit.api.Git; | |
import org.eclipse.jgit.lib.Repository; | |
import org.eclipse.jgit.revwalk.RevCommit; | |
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; | |
import java.io.File; | |
import java.util.Date; | |
/** | |
* Created by Noor on 3/27/17. | |
*/ | |
public class GitCommitLog { | |
public void log() throws Exception{ | |
FileRepositoryBuilder builder = new FileRepositoryBuilder(); | |
Repository repo = builder.setGitDir(new File("/path/to/repo" + "/.git")) | |
.setMustExist(true).build(); | |
Git git = new Git(repo); | |
Iterable<RevCommit> log = git.log() | |
//.add(repo.resolve("master")) | |
//.addRange(repo.resolve("1406d4267a6b0006d9a1b1daa6152aa9a046e2a0"), repo.resolve("3ef5115aaa23d03289fb68af19abd6acd935c057")) | |
//.setMaxCount(3) | |
//.addPath("domain/src/main/java/io/noorulhaq/functional/banking/domain/algebra/AccountService.java") | |
.call(); | |
for (RevCommit commit : log) { | |
System.out.println(" >>>>>>>>> " + commit.getName()); | |
System.out.println(" >>>>>>>>> " + new Date(commit.getCommitTime())); | |
System.out.println(" >>>>>>>>> " + commit.getAuthorIdent().getName()); | |
System.out.println(" >>>>>>>>> " + commit.getCommitterIdent().getName()); | |
System.out.println(" >>>>>>>>> " + commit.getFullMessage()); | |
System.out.println("----------------------------------------------------------------"); | |
} | |
git.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment