I started writing a library called gitective , which contains many helpers for working with blobs, commits and trees using JGit and is MIT licensed and available on GitHub.
Get file contents in HEAD commit
Repository repo = new FileRepository("/repos/project/.git"); String content = BlobUtils.getHeadContent(repo, "src/Buffer.java");
Get the contents of a file on a branch
Repository repo = new FileRepository("/repos/project/.git"); String content = BlobUtils.getContent(repo, "master", "src/Buffer.java");
Reset two files
Repository repo = new FileRepository("/repos/project/.git"); ObjectId current = BlobUtils.getId(repo, "master", "Main.java"); ObjectId previous = BlobUtils.getId(repo, "master~1", "Main.java"); Collection<Edit> edit = BlobUtils.diff(repo, previous, current);
Additional examples of the provided utilities are described in detail in README .
Kevin Sawicki Nov 03 2018-11-11T00: 00Z
source share