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

public Class LogCommand

extends GitCommand<Iterable<RevCommit>>
Class Inheritance
Imports
java.io.IOException, java.text.MessageFormat, java.util.ArrayList, .List, org.eclipse.jgit.api.errors.GitAPIException, .JGitInternalException, .NoHeadException, org.eclipse.jgit.errors.IncorrectObjectTypeException, .MissingObjectException, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.lib.AnyObjectId, .Constants, .ObjectId, .Ref, .Repository, org.eclipse.jgit.revwalk.RevCommit, .RevWalk, org.eclipse.jgit.revwalk.filter.AndRevFilter, .MaxCountRevFilter, .RevFilter, .SkipRevFilter, org.eclipse.jgit.treewalk.filter.AndTreeFilter, .PathFilter, .PathFilterGroup, .TreeFilter

A class used to execute a Log command. It has setters for all supported options and arguments of this command and a call() method to finally execute the command. Each instance of this class should only be used for one invocation of the command (means: one call to call())

Examples (git is a org.eclipse.jgit.api.Git instance):

Get newest 10 commits, starting from the current branch:

ObjectId head = repository.resolve(Constants.HEAD);

Iterable<RevCommit> commits = git.log().add(head).setMaxCount(10).call();

Get commits only for a specific file:

git.log().add(head).addPath("dir/filename.txt").call();
See Also
Git documentation about Log

Field Summary

Modifier and TypeField and Description
private final List<TreeFilter>
private int
private final List<PathFilter>
private RevFilter
private int
private boolean
private RevWalk
Inherited from org.eclipse.jgit.api.GitCommand:
repo

Constructor Summary

AccessConstructor and Description
protected
LogCommand(Repository repo)

Constructor for LogCommand.

Method Summary

Modifier and TypeMethod and Description
public LogCommand

Returns:

this
add
(AnyObjectId
the id of the commit to start from
start
)

Mark a commit to start graph traversal from.

private LogCommand
add(boolean include, AnyObjectId start)

public LogCommand

Returns:

this
addPath
(String
a repository-relative path (with / as separator)
path
)

Show only commits that affect any of the specified paths.

public LogCommand

Returns:

this
addRange
(AnyObjectId since, AnyObjectId until)

Adds the range since..until

public LogCommand

Returns:

this
all
()

Add all refs as commits to start the graph traversal from.

public Iterable<RevCommit>
call()

Implements abstract org.eclipse.jgit.api.GitCommand.call.

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

public LogCommand

Returns:

this
excludePath
(String
a repository-relative path (with / as separator)
path
)

Show all commits that are not within any of the specified paths.

public LogCommand

Returns:

this
not
(AnyObjectId start)

Same as --not start, or ^start

public LogCommand

Returns:

this
setMaxCount
(int
the limit
maxCount
)

Limit the number of commits to output.

public LogCommand

Returns:

this
setRevFilter
(RevFilter
the filter that this instance of LogCommand should use
aFilter
)

Set a filter for the LogCommand.

public LogCommand

Returns:

this
setSkip
(int
the number of commits to skip
skip
)

Skip the number of commits before starting to show the commit output.

Inherited from org.eclipse.jgit.api.GitCommand:
checkCallablegetRepositorysetCallable

Field Detail

excludeTreeFiltersback to summary
private final List<TreeFilter> excludeTreeFilters
maxCountback to summary
private int maxCount
pathFiltersback to summary
private final List<PathFilter> pathFilters
revFilterback to summary
private RevFilter revFilter
skipback to summary
private int skip
startSpecifiedback to summary
private boolean startSpecified
walkback to summary
private RevWalk walk

Constructor Detail

LogCommandback to summary
protected LogCommand(Repository repo)

Constructor for LogCommand.

Parameters
repo:Repository

the org.eclipse.jgit.lib.Repository

Method Detail

addback to summary
public LogCommand add(AnyObjectId start) throws MissingObjectException, IncorrectObjectTypeException

Mark a commit to start graph traversal from.

Parameters
start:AnyObjectId

the id of the commit to start from

Returns:LogCommand

this

Exceptions
MissingObjectException:
the commit supplied is not available from the object database. This usually indicates the supplied commit is invalid, but the reference was constructed during an earlier invocation to org.eclipse.jgit.revwalk.RevWalk#lookupCommit(AnyObjectId).
IncorrectObjectTypeException:
the object was not parsed yet and it was discovered during parsing that it is not actually a commit. This usually indicates the caller supplied a non-commit SHA-1 to org.eclipse.jgit.revwalk.RevWalk#lookupCommit(AnyObjectId).
JGitInternalException:
a low-level exception of JGit has occurred. The original exception can be retrieved by calling java.lang.Exception#getCause(). Expect only IOException's to be wrapped. Subclasses of java.io.IOException (e.g. org.eclipse.jgit.errors.MissingObjectException) are typically not wrapped here but thrown as original exception
See Also
RevWalk#markStart(RevCommit)
addback to summary
private LogCommand add(boolean include, AnyObjectId start) throws MissingObjectException, IncorrectObjectTypeException, JGitInternalException
addPathback to summary
public LogCommand addPath(String path)

Show only commits that affect any of the specified paths. The path must either name a file or a directory exactly and use / (slash) as separator. Note that regex expressions or wildcards are not supported.

Parameters
path:String

a repository-relative path (with / as separator)

Returns:LogCommand

this

addRangeback to summary
public LogCommand addRange(AnyObjectId since, AnyObjectId until) throws MissingObjectException, IncorrectObjectTypeException

Adds the range since..until

Parameters
since:AnyObjectId

a org.eclipse.jgit.lib.AnyObjectId object.

until:AnyObjectId

a org.eclipse.jgit.lib.AnyObjectId object.

Returns:LogCommand

this

Exceptions
MissingObjectException:
the commit supplied is not available from the object database. This usually indicates the supplied commit is invalid, but the reference was constructed during an earlier invocation to org.eclipse.jgit.revwalk.RevWalk#lookupCommit(AnyObjectId).
IncorrectObjectTypeException:
the object was not parsed yet and it was discovered during parsing that it is not actually a commit. This usually indicates the caller supplied a non-commit SHA-1 to org.eclipse.jgit.revwalk.RevWalk#lookupCommit(AnyObjectId).
JGitInternalException:
a low-level exception of JGit has occurred. The original exception can be retrieved by calling java.lang.Exception#getCause(). Expect only IOException's to be wrapped. Subclasses of java.io.IOException (e.g. org.eclipse.jgit.errors.MissingObjectException) are typically not wrapped here but thrown as original exception
allback to summary
public LogCommand all() throws IOException

Add all refs as commits to start the graph traversal from.

Returns:LogCommand

this

Exceptions
IOException:
the references could not be accessed
See Also
add(AnyObjectId)
callback to summary
public Iterable<RevCommit> call() throws GitAPIException, NoHeadException

Implements abstract org.eclipse.jgit.api.GitCommand.call.

Implements java.util.concurrent.Callable.call.

Doc from org.eclipse.jgit.api.GitCommand.call.

Computes a result, or throws an exception if unable to do so.

Execute the command

Executes the Log command with all the options and parameters collected by the setter methods (e.g. add(AnyObjectId), not(AnyObjectId), ..) of this class. Each instance of this class should only be used for one invocation of the command. Don't call this method twice on an instance.

Returns:Iterable<RevCommit>

Doc from java.util.concurrent.Callable.call.

computed result

Annotations
@Override
excludePathback to summary
public LogCommand excludePath(String path)

Show all commits that are not within any of the specified paths. The path must either name a file or a directory exactly and use / (slash) as separator. Note that regular expressions or wildcards are not yet supported. If a path is both added and excluded from the search, then the exclusion wins.

Parameters
path:String

a repository-relative path (with / as separator)

Returns:LogCommand

this

Since
5.6
notback to summary
public LogCommand not(AnyObjectId start) throws MissingObjectException, IncorrectObjectTypeException

Same as --not start, or ^start

Parameters
start:AnyObjectId

a org.eclipse.jgit.lib.AnyObjectId

Returns:LogCommand

this

Exceptions
MissingObjectException:
the commit supplied is not available from the object database. This usually indicates the supplied commit is invalid, but the reference was constructed during an earlier invocation to org.eclipse.jgit.revwalk.RevWalk#lookupCommit(AnyObjectId).
IncorrectObjectTypeException:
the object was not parsed yet and it was discovered during parsing that it is not actually a commit. This usually indicates the caller supplied a non-commit SHA-1 to org.eclipse.jgit.revwalk.RevWalk#lookupCommit(AnyObjectId).
JGitInternalException:
a low-level exception of JGit has occurred. The original exception can be retrieved by calling java.lang.Exception#getCause(). Expect only IOException's to be wrapped. Subclasses of java.io.IOException (e.g. org.eclipse.jgit.errors.MissingObjectException) are typically not wrapped here but thrown as original exception
setMaxCountback to summary
public LogCommand setMaxCount(int maxCount)

Limit the number of commits to output.

Parameters
maxCount:int

the limit

Returns:LogCommand

this

setRevFilterback to summary
public LogCommand setRevFilter(RevFilter aFilter)

Set a filter for the LogCommand.

Parameters
aFilter:RevFilter

the filter that this instance of LogCommand should use

Returns:LogCommand

this

Since
4.4
setSkipback to summary
public LogCommand setSkip(int skip)

Skip the number of commits before starting to show the commit output.

Parameters
skip:int

the number of commits to skip

Returns:LogCommand

this