Concepts | ||
---|---|---|
![]() |
![]() |
|
JGit User Guide | Reference |
A Repository holds all objects and refs used for managing source code.
To build a repository, you invoke flavors of RepositoryBuilder.
<source lang="java"> FileRepositoryBuilder builder = new RepositoryBuilder(); Repository repository = builder.setGitDir("/my/git/directory") .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); </source>
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.
<source lang="java"> ObjectId head = repository.resolve("HEAD"); </source>
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
<source lang="java"> Ref HEAD = repository.getRef("refs/heads/master"); </source>
A RevWalk walks a commit graph and produces the matching commits in order.
<source lang="java"> RevWalk walk = new RevWalk(repository); </source>
TODO talk about filters
A RevCommit represents a commit in the Git object model.
To parse a commit, simply use a RevWalk instance:
<source lang="java"> RevWalk walk = new RevWalk(repository); RevCommit commit = walk.parseCommit(objectIdOfCommit); </source>
A RevTag represents a tag in the Git object model.
To parse a tag, simply use a RevWalk instance:
<source lang="java"> RevWalk walk = new RevWalk(repository); RevTag tag = walk.parseTag(objectIdOfTag); </source>
A RevTree represents a tree in the Git object model.
To parse a commit, simply use a RevWalk instance:
<source lang="java"> RevWalk walk = new RevWalk(repository); RevTree tree = walk.parseTree(objectIdOfTree); </source>
![]() |
![]() |
![]() |
JGit User Guide | Reference |