public static void main(String[] args) throws IOException, InvalidRefNameException, GitAPIException { Repository repository = CookbookHelper.openJGitCookbookRepository(); Git git = new Git(repository); Iterable<RevCommit> commits = git.log().all().call(); int count = 0; for (RevCommit commit : commits) { System.out.println("LogCommit: " + commit); count++; } System.out.println(count); repository.close(); }
public static void main(String[] args) throws IOException, GitAPIException { // prepare a new test-repository try (Repository repository = CookbookHelper.createNewRepository()) { try (Git git = new Git(repository)) { // create the file File myfile = new File(repository.getDirectory().getParent(), "testfile"); myfile.createNewFile(); // run the add git.add().addFilepattern("testfile").call(); // and then commit the changes git.commit().setMessage("Added testfile").call(); System.out.println( "Committed file " + myfile + " to repository at " + repository.getDirectory()); } } }
public static void main(String[] args) throws IOException, GitAPIException { Repository repository = CookbookHelper.openJGitCookbookRepository(); Iterable<RevCommit> logs = new Git(repository).log().all().call(); int count = 0; for (RevCommit rev : logs) { System.out.println( "Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */); count++; } System.out.println("Had " + count + " commits overall on current branch"); logs = new Git(repository) .log() // for all log.all() .addPath("README.md") .call(); count = 0; for (RevCommit rev : logs) { System.out.println( "Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */); count++; } System.out.println("Had " + count + " commits on README.md"); logs = new Git(repository) .log() // for all log.all() .addPath("pom.xml") .call(); count = 0; for (RevCommit rev : logs) { System.out.println( "Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */); count++; } System.out.println("Had " + count + " commits on pom.xml"); repository.close(); }
public static void main(String[] args) throws IOException, GitAPIException { Repository repository = CookbookHelper.openJGitCookbookRepository(); List<Ref> refs = new Git(repository).branchList().call(); for (Ref ref : refs) { System.out.println( "Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName()); listReflog(repository, ref); } List<Ref> call = new Git(repository).tagList().call(); for (Ref ref : call) { System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName()); listReflog(repository, ref); } repository.close(); }