Package org.eclipse.jgit.api

## Class LogCommand

- java.lang.Object
- - org.eclipse.jgit.api.GitCommand<Iterable<RevCommit>>
  - - org.eclipse.jgit.api.LogCommand

All Implemented Interfaces:
  `Callable<Iterable<RevCommit>>`

    public class LogCommand
    extends GitCommand<Iterable<RevCommit>>

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 `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

### Fields inherited from class org.eclipse.jgit.api.GitCommand

`repo`

### Constructor Summary

Constructors
`protected` `LogCommand​(Repository repo)`

### Method Summary

All Methods Instance Methods Concrete Methods
`LogCommand` `add​(AnyObjectId start)` Mark a commit to start graph traversal from.
`LogCommand` `addPath​(String path)` Show only commits that affect any of the specified paths.
`LogCommand` `addRange​(AnyObjectId since, AnyObjectId until)` Adds the range `since..until`
`LogCommand` `all()` Add all refs as commits to start the graph traversal from.
`Iterable<RevCommit>` `call()` Executes the `Log` command with all the options and parameters collected by the setter methods (e.g.
`LogCommand` `not​(AnyObjectId start)` Same as `--not start`, or `^start`
`LogCommand` `setMaxCount​(int maxCount)` Limit the number of commits to output.
`LogCommand` `setSkip​(int skip)` Skip the number of commits before starting to show the commit output.

### Methods inherited from class org.eclipse.jgit.api.GitCommand

`checkCallable, getRepository, setCallable`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### LogCommand

    protected LogCommand​(Repository repo)

Parameters:
  `repo` -

### Method Detail

#### call

    public Iterable<RevCommit> call()
                             throws GitAPIException,
                                    NoHeadException

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.

Specified by:
  `call` in interface `Callable<Iterable<RevCommit>>`
Specified by:
  `call` in class `GitCommand<Iterable<RevCommit>>`
Returns:
  an iteration over RevCommits
Throws:
  `NoHeadException` - of the references ref cannot be resolved
  `GitAPIException` - or subclass thereof when an error occurs

#### add

    public LogCommand add​(AnyObjectId start)
                   throws MissingObjectException,
                          IncorrectObjectTypeException

Mark a commit to start graph traversal from.

Parameters:
  `start` -
Returns:
  `this`
Throws:
  `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 `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 `RevWalk.lookupCommit(AnyObjectId)`.
  `JGitInternalException` - a low-level exception of JGit has occurred. The original exception can be retrieved by calling `Throwable.getCause()`. Expect only `IOException's` to be wrapped. Subclasses of `IOException` (e.g. `MissingObjectException`) are typically not wrapped here but thrown as original exception
See Also:
  `RevWalk.markStart(RevCommit)`

#### not

    public LogCommand not​(AnyObjectId start)
                   throws MissingObjectException,
                          IncorrectObjectTypeException

Same as `--not start`, or `^start`

Parameters:
  `start` -
Returns:
  `this`
Throws:
  `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 `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 `RevWalk.lookupCommit(AnyObjectId)`.
  `JGitInternalException` - a low-level exception of JGit has occurred. The original exception can be retrieved by calling `Throwable.getCause()`. Expect only `IOException's` to be wrapped. Subclasses of `IOException` (e.g. `MissingObjectException`) are typically not wrapped here but thrown as original exception

#### addRange

    public LogCommand addRange​(AnyObjectId since,
                               AnyObjectId until)
                        throws MissingObjectException,
                               IncorrectObjectTypeException

Adds the range `since..until`

Parameters:
  `since` -
  `until` -
Returns:
  `this`
Throws:
  `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 `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 `RevWalk.lookupCommit(AnyObjectId)`.
  `JGitInternalException` - a low-level exception of JGit has occurred. The original exception can be retrieved by calling `Throwable.getCause()`. Expect only `IOException's` to be wrapped. Subclasses of `IOException` (e.g. `MissingObjectException`) are typically not wrapped here but thrown as original exception

#### all

    public LogCommand all()
                   throws IOException

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

Returns:
  `this`
Throws:
  `IOException` - the references could not be accessed
See Also:
  `add(AnyObjectId)`

#### addPath

    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` - a repository-relative path (with `/` as separator)
Returns:
  `this`

#### setSkip

    public LogCommand setSkip​(int skip)

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

Parameters:
  `skip` - the number of commits to skip
Returns:
  `this`

#### setMaxCount

    public LogCommand setMaxCount​(int maxCount)

Limit the number of commits to output.

Parameters:
  `maxCount` - the limit
Returns:
  `this`