All objects are represented by a SHA-1 id in the Git object model. In JGit, this is represented by the AnyObjectId and ObjectId classes.
There are four types of objects in the Git object model:
To resolve an object from a repository, simply pass in the right revision string.
ObjectId head = repository.resolve("HEAD");
A ref is a variable that holds a single object identifier. The object identifier can be any valid Git object (blob, tree, commit, tag).
For example, to query for the reference to head, you can simply call
Ref HEAD = repository.getRef("refs/heads/master");
A RevWalk walks a commit graph and produces the matching commits in order.
RevWalk walk = new RevWalk(repository);
TODO talk about filters
A RevCommit represents a commit in the Git object model.
To parse a commit, simply use a RevWalk instance:
RevWalk walk = new RevWalk(repository); RevCommit commit = walk.parseCommit(objectIdOfCommit);
A RevTag represents a tag in the Git object model.
To parse a tag, simply use a RevWalk instance:
RevWalk walk = new RevWalk(repository); RevTag tag = walk.parseTag(objectIdOfTag);
A RevTree represents a tree in the Git object model.
To parse a tree, simply use a RevWalk instance:
RevWalk walk = new RevWalk(repository); RevTree tree = walk.parseTree(objectIdOfTree);
While JGit contains a lot of low level code to work with Git repositories, it also contains a higher level API that mimics some of the Git porcelain commands in the org.eclipse.jgit.api package.
Most users of JGit should start here.
AddCommand allows you to add files to the index and has options available via its setter methods.
Here's a quick example of how to add a set of files to the index using the porcelain API.
Git git = new Git(db); AddCommand add = git.add(); add.addFilepattern("someDirectory").call();
CommitCommand allows you to perform commits and has options available via its setter methods.
Here's a quick example of how to commit using the porcelain API.
Git git = new Git(db); CommitCommand commit = git.commit(); commit.setMessage("initial commit").call();
TagCommand supports a variety of tagging options through its setter methods.
Here's a quick example of how to tag a commit using the porcelain API.
Git git = new Git(db); RevCommit commit = git.commit().setMessage("initial commit").call(); RevTag tag = git.tag().setName("tag").call();
LogCommand allows you to easily walk a commit graph.
Here's a quick example of how get some log messages.
Git git = new Git(db); Iterable<RevCommit> log = git.log().call();
GitHub is a Web-based Git repository hosting service. It offers all of the distributed revision control and source code management (SCM) functionality of Git as well as adding its own features.
Learn MoreGit is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Learn MoreEGit is an Eclipse Team provider for the Git version control system. Git is a distributed SCM, which means every developer has a full copy of all history of every revision of the code, making queries against the history very fast and versatile.
Learn More