JGit User Guide - Reference

# Reference

## Porcelain API

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 (git-add)

AddCommand allows you to add files to the index and has options available via its setter methods.

- addFilepattern()

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 (git-commit)

CommitCommand allows you to perform commits and has options available via its setter methods.

- setAuthor()
- setCommitter()
- setAll()

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 (git-tag)

TagCommand supports a variety of tagging options through its setter methods.

- setName()
- setMessage()
- setTagger()
- setObjectId()
- setForceUpdate()
- setSigned() - not supported yet, will throw exception

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 (git-log)

LogCommand allows you to easily walk a commit graph.

- add(AnyObjectId start)
- addRange(AnyObjectId since, AnyObjectId until)

Here's a quick example of how get some log messages.

    Git git = new Git(db);
    Iterable<RevCommit> log = git.log().call();

### MergeCommand (git-merge)

TODO

## Ant Tasks

JGit has Ant tasks for some common tasks contained in the org.eclipse.jgit.ant bundle.

To use these tasks:

       <taskdef resource="org/eclipse/jgit/ant/ant-tasks.properties">
           <classpath>
             <pathelement location="path/to/org.eclipse.jgit.ant-VERSION.jar"/>
             <pathelement location="path/to/org.eclipse.jgit-VERSION.jar"/>
             <pathelement location="path/to/jsch-0.1.44-1.jar"/>
           </classpath>
       </taskdef>

This would then provide git-clone, git-init and git-checkout tasks.

### git-clone

       <git-clone uri="http://egit.eclipse.org/jgit.git" />

The following attributes are required:

- uri: the uri to clone from

The following attributes are optional:

- dest: the destination to clone to (defaults to use a human readable directory name based on the last path component of the uri)
- bare: true/false/yes/no to indicate if the cloned repository should be bare or not (defaults to false)
- branch: the initial branch to check out when cloning the repository (defaults to HEAD)

### git-init

       <git-init />

The following attributes are optional:

- dest: the path where a git repository is initialized (defaults $GIT_DIR or the current directory)
- bare: true/false/yes/no to indicate if the repository should be bare or not (defaults to false)

### git-checkout

       <git-checkout src="path/to/repo" branch="origin/experimental" />

The following attributes are required:

- src: the path to the git repository
- branch: the initial branch to checkout

The following attributes are optional:

- createbranch: true/false/yes/no to indicate whether the branch should be created if it does not already exist (defaults to false)
- force: true/false/yes/no: if true/yes and the branch with the given name already exists, the start-point of an existing branch will be set to a new start-point; if false, the existing branch will not be changed (defaults to false)

### git-add

TODO