Top Description Fields Constructors Methods
org.eclipse.jgit.lib

public Class CommitBuilder

extends ObjectBuilder
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.UTF_8

Mutable builder to construct a commit recording the state of a project. Applications should use this object when they need to manually construct a commit and want precise control over its fields. For a higher level interface see org.eclipse.jgit.api.CommitCommand. To read a commit object, construct a org.eclipse.jgit.revwalk.RevWalk and obtain a org.eclipse.jgit.revwalk.RevCommit instance by calling org.eclipse.jgit.revwalk.RevWalk#parseCommit(AnyObjectId).

Field Summary

Modifier and TypeField and Description
private PersonIdent
private static final ObjectId[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private ObjectId[]
private ObjectId

Constructor Summary

AccessConstructor and Description
public
CommitBuilder()

Initialize an empty commit.

Method Summary

Modifier and TypeMethod and Description
public void
addParentId(AnyObjectId
new parent to add onto the end of the current parent list.
additionalParent
)

Add a parent onto the end of the parent list.

public byte[]
build()

Implements abstract org.eclipse.jgit.lib.ObjectBuilder.build.

Format this builder's state as a git object.

public PersonIdent

Returns:

the author of this commit (who wrote it).
getAuthor
()

Overrides org.eclipse.jgit.lib.ObjectBuilder.getAuthor.

Get the author of this commit (who wrote it).

public PersonIdent

Returns:

the committer and commit time for this object.
getCommitter
()

Get the committer and commit time for this object.

public ObjectId[]

Returns:

the ancestors of this commit. Never null.
getParentIds
()

Get the ancestors of this commit.

public ObjectId

Returns:

id of the root tree listing this commit's snapshot.
getTreeId
()

Get id of the root tree listing this commit's snapshot.

public void
setAuthor(PersonIdent
the new author. Should not be null.
newAuthor
)

Overrides org.eclipse.jgit.lib.ObjectBuilder.setAuthor.

Set the author (name, email address, and date) of who wrote the commit.

public void
setCommitter(PersonIdent
the committer information. Should not be null.
newCommitter
)

Set the committer and commit time for this object.

public void
setParentId(AnyObjectId
the single parent for the commit.
newParent
)

Set the parent of this commit.

public void
setParentIds(AnyObjectId
the first parent of this commit. Typically this is the current value of the HEAD reference and is thus the current branch's position in history.
parent1
,
AnyObjectId
the second parent of this merge commit. Usually this is the branch being merged into the current branch.
parent2
)

Set the parents of this commit.

public void
setParentIds(ObjectId...
the entire list of parents for this commit.
newParents
)

Set the parents of this commit.

public void
setParentIds(List<? extends AnyObjectId>
the entire list of parents for this commit.
newParents
)

Set the parents of this commit.

public void
setTreeId(AnyObjectId
the tree identity.
id
)

Set the tree id for this commit object.

public byte[]

Returns:

this object in the canonical commit format, suitable for storage in a repository.
toByteArray
()

Format this builder's state as a commit object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.eclipse.jgit.lib.ObjectBuilder:
getEncodinggetGpgSignaturegetMessagesetEncodingsetGpgSignaturesetMessagewriteEncodingwriteMultiLineHeader

Field Detail

committerback to summary
private PersonIdent committer
EMPTY_OBJECTID_LISTback to summary
private static final ObjectId[] EMPTY_OBJECTID_LIST
hauthorback to summary
private static final byte[] hauthor
hcommitterback to summary
private static final byte[] hcommitter
hgpgsigback to summary
private static final byte[] hgpgsig
hparentback to summary
private static final byte[] hparent
htreeback to summary
private static final byte[] htree
parentIdsback to summary
private ObjectId[] parentIds
treeIdback to summary
private ObjectId treeId

Constructor Detail

CommitBuilderback to summary
public CommitBuilder()

Initialize an empty commit.

Method Detail

addParentIdback to summary
public void addParentId(AnyObjectId additionalParent)

Add a parent onto the end of the parent list.

Parameters
additionalParent:AnyObjectId

new parent to add onto the end of the current parent list.

buildback to summary
public byte[] build() throws UnsupportedEncodingException

Implements abstract org.eclipse.jgit.lib.ObjectBuilder.build.

Doc from org.eclipse.jgit.lib.ObjectBuilder.build.

Format this builder's state as a git object.

Returns:byte[]

this object in the canonical git format, suitable for storage in a repository.

Annotations
@Override
Exceptions
UnsupportedEncodingException:
the encoding specified by getEncoding() is not supported by this Java runtime.
getAuthorback to summary
public PersonIdent getAuthor()

Overrides org.eclipse.jgit.lib.ObjectBuilder.getAuthor.

Get the author of this commit (who wrote it).

Returns:PersonIdent

the author of this commit (who wrote it).

Annotations
@Override
getCommitterback to summary
public PersonIdent getCommitter()

Get the committer and commit time for this object.

Returns:PersonIdent

the committer and commit time for this object.

getParentIdsback to summary
public ObjectId[] getParentIds()

Get the ancestors of this commit.

Returns:ObjectId[]

the ancestors of this commit. Never null.

getTreeIdback to summary
public ObjectId getTreeId()

Get id of the root tree listing this commit's snapshot.

Returns:ObjectId

id of the root tree listing this commit's snapshot.

setAuthorback to summary
public void setAuthor(PersonIdent newAuthor)

Overrides org.eclipse.jgit.lib.ObjectBuilder.setAuthor.

Set the author (name, email address, and date) of who wrote the commit.

Parameters
newAuthor:PersonIdent

the new author. Should not be null.

Annotations
@Override
setCommitterback to summary
public void setCommitter(PersonIdent newCommitter)

Set the committer and commit time for this object.

Parameters
newCommitter:PersonIdent

the committer information. Should not be null.

setParentIdback to summary
public void setParentId(AnyObjectId newParent)

Set the parent of this commit.

Parameters
newParent:AnyObjectId

the single parent for the commit.

setParentIdsback to summary
public void setParentIds(AnyObjectId parent1, AnyObjectId parent2)

Set the parents of this commit.

Parameters
parent1:AnyObjectId

the first parent of this commit. Typically this is the current value of the HEAD reference and is thus the current branch's position in history.

parent2:AnyObjectId

the second parent of this merge commit. Usually this is the branch being merged into the current branch.

setParentIdsback to summary
public void setParentIds(ObjectId... newParents)

Set the parents of this commit.

Parameters
newParents:ObjectId[]

the entire list of parents for this commit.

setParentIdsback to summary
public void setParentIds(List<? extends AnyObjectId> newParents)

Set the parents of this commit.

Parameters
newParents:List<? extends AnyObjectId>

the entire list of parents for this commit.

setTreeIdback to summary
public void setTreeId(AnyObjectId id)

Set the tree id for this commit object.

Parameters
id:AnyObjectId

the tree identity.

toByteArrayback to summary
public byte[] toByteArray() throws UnsupportedEncodingException

Format this builder's state as a commit object.

Returns:byte[]

this object in the canonical commit format, suitable for storage in a repository.

Exceptions
UnsupportedEncodingException:
the encoding specified by getEncoding() is not supported by this Java runtime.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@SuppressWarnings:nls
@Override