org.eclipse.jgit.api
Class Git

java.lang.Object
  extended by org.eclipse.jgit.api.Git

public class Git
extends Object

Offers a "GitPorcelain"-like API to interact with a git repository.

The GitPorcelain commands are described in the Git Documentation.

This class only offers methods to construct so-called command classes. Each GitPorcelain command is represented by one command class.
Example: this class offers a commit() method returning an instance of the CommitCommand class. The CommitCommand class has setters for all the arguments and options. The CommitCommand class also has a call method to actually execute the commit. The following code show's how to do a simple commit:

 Git git = new Git(myRepo);
 git.commit().setMessage("Fix393").setAuthor(developerIdent).call();
 
All mandatory parameters for commands have to be specified in the methods of this class, the optional parameters have to be specified by the setter-methods of the Command class.

This class is intended to be used internally (e.g. by JGit tests) or by external components (EGit, third-party tools) when they need exactly the functionality of a GitPorcelain command. There are use-cases where this class is not optimal and where you should use the more low-level JGit classes. The methods in this class may for example offer too much functionality or they offer the functionality with the wrong arguments.


Constructor Summary
Git(Repository repo)
          Constructs a new Git object which can interact with the specified git repository.
 
Method Summary
 AddCommand add()
          Returns a command object to execute a Add command
 ApplyCommand apply()
          Returns a command object to execute a apply command
 BlameCommand blame()
          Returns a command object to execute a blame command
 CreateBranchCommand branchCreate()
          Returns a command object used to create branches
 DeleteBranchCommand branchDelete()
          Returns a command object used to delete branches
 ListBranchCommand branchList()
          Returns a command object used to list branches
 RenameBranchCommand branchRename()
          Returns a command object used to rename branches
 CheckoutCommand checkout()
          Returns a command object to execute a checkout command
 CherryPickCommand cherryPick()
          Returns a command object to execute a cherry-pick command
 CleanCommand clean()
          Returns a command object to execute a clean command
static CloneCommand cloneRepository()
          Returns a command object to execute a clone command
 CommitCommand commit()
          Returns a command object to execute a Commit command
 DiffCommand diff()
          Returns a command object to execute a diff command
 FetchCommand fetch()
          Returns a command object to execute a Fetch command
 GarbageCollectCommand gc()
          Returns a command object to execute a gc command
 Repository getRepository()
           
static InitCommand init()
          Returns a command object to execute a init command
 LogCommand log()
          Returns a command object to execute a Log command
 LsRemoteCommand lsRemote()
          Returns a command object to execute a ls-remote command
 MergeCommand merge()
          Returns a command object to execute a Merge command
 AddNoteCommand notesAdd()
          Returns a command to add notes to an object
 ListNotesCommand notesList()
          Returns a command to list all notes
 RemoveNoteCommand notesRemove()
          Returns a command to remove notes on an object
 ShowNoteCommand notesShow()
          Returns a command to show notes on an object
static Git open(File dir)
           
static Git open(File dir, FS fs)
           
 PullCommand pull()
          Returns a command object to execute a Pull command
 PushCommand push()
          Returns a command object to execute a Push command
 RebaseCommand rebase()
          Returns a command object to execute a Rebase command
 ReflogCommand reflog()
          Returns a command object to execute a reflog command
 ResetCommand reset()
          Returns a command object to execute a reset command
 RevertCommand revert()
          Returns a command object to execute a revert command
 RmCommand rm()
          Returns a command object to execute a rm command
 StashApplyCommand stashApply()
          Returns a command object used to apply a stashed commit
 StashCreateCommand stashCreate()
          Returns a command object used to create a stashed commit
 StashDropCommand stashDrop()
          Returns a command object used to drop a stashed commit
 StashListCommand stashList()
          Returns a command object used to list stashed commits
 StatusCommand status()
          Returns a command object to execute a status command
 SubmoduleAddCommand submoduleAdd()
          Returns a command object to execute a submodule add command
 SubmoduleInitCommand submoduleInit()
          Returns a command object to execute a submodule init command
 SubmoduleStatusCommand submoduleStatus()
          Returns a command object to execute a submodule status command
 SubmoduleSyncCommand submoduleSync()
          Returns a command object to execute a submodule sync command
 SubmoduleUpdateCommand submoduleUpdate()
          Returns a command object to execute a submodule update command
 TagCommand tag()
          Returns a command object to execute a Tag command
 DeleteTagCommand tagDelete()
          Returns a command object used to delete tags
 ListTagCommand tagList()
          Returns a command object used to list tags
static Git wrap(Repository repo)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Git

public Git(Repository repo)
Constructs a new Git object which can interact with the specified git repository. All command classes returned by methods of this class will always interact with this git repository.

Parameters:
repo - the git repository this class is interacting with. null is not allowed
Method Detail

open

public static Git open(File dir)
                throws IOException
Parameters:
dir - the repository to open. May be either the GIT_DIR, or the working tree directory that contains .git.
Returns:
a Git object for the existing git repository
Throws:
IOException

open

public static Git open(File dir,
                       FS fs)
                throws IOException
Parameters:
dir - the repository to open. May be either the GIT_DIR, or the working tree directory that contains .git.
fs - filesystem abstraction to use when accessing the repository.
Returns:
a Git object for the existing git repository
Throws:
IOException

wrap

public static Git wrap(Repository repo)
Parameters:
repo - the git repository this class is interacting with. null is not allowed
Returns:
a Git object for the existing git repository

cloneRepository

public static CloneCommand cloneRepository()
Returns a command object to execute a clone command

Returns:
a CloneCommand used to collect all optional parameters and to finally execute the clone command
See Also:
Git documentation about clone

init

public static InitCommand init()
Returns a command object to execute a init command

Returns:
a InitCommand used to collect all optional parameters and to finally execute the init command
See Also:
Git documentation about init

commit

public CommitCommand commit()
Returns a command object to execute a Commit command

Returns:
a CommitCommand used to collect all optional parameters and to finally execute the Commit command
See Also:
Git documentation about Commit

log

public LogCommand log()
Returns a command object to execute a Log command

Returns:
a LogCommand used to collect all optional parameters and to finally execute the Log command
See Also:
Git documentation about Log

merge

public MergeCommand merge()
Returns a command object to execute a Merge command

Returns:
a MergeCommand used to collect all optional parameters and to finally execute the Merge command
See Also:
Git documentation about Merge

pull

public PullCommand pull()
Returns a command object to execute a Pull command

Returns:
a PullCommand

branchCreate

public CreateBranchCommand branchCreate()
Returns a command object used to create branches

Returns:
a CreateBranchCommand

branchDelete

public DeleteBranchCommand branchDelete()
Returns a command object used to delete branches

Returns:
a DeleteBranchCommand

branchList

public ListBranchCommand branchList()
Returns a command object used to list branches

Returns:
a ListBranchCommand

tagList

public ListTagCommand tagList()
Returns a command object used to list tags

Returns:
a ListTagCommand

branchRename

public RenameBranchCommand branchRename()
Returns a command object used to rename branches

Returns:
a RenameBranchCommand

add

public AddCommand add()
Returns a command object to execute a Add command

Returns:
a AddCommand used to collect all optional parameters and to finally execute the Add command
See Also:
Git documentation about Add

tag

public TagCommand tag()
Returns a command object to execute a Tag command

Returns:
a TagCommand used to collect all optional parameters and to finally execute the Tag command
See Also:
Git documentation about Tag

fetch

public FetchCommand fetch()
Returns a command object to execute a Fetch command

Returns:
a FetchCommand used to collect all optional parameters and to finally execute the Fetch command
See Also:
Git documentation about Fetch

push

public PushCommand push()
Returns a command object to execute a Push command

Returns:
a PushCommand used to collect all optional parameters and to finally execute the Push command
See Also:
Git documentation about Push

cherryPick

public CherryPickCommand cherryPick()
Returns a command object to execute a cherry-pick command

Returns:
a CherryPickCommand used to collect all optional parameters and to finally execute the cherry-pick command
See Also:
Git documentation about cherry-pick

revert

public RevertCommand revert()
Returns a command object to execute a revert command

Returns:
a RevertCommand used to collect all optional parameters and to finally execute the cherry-pick command
See Also:
Git documentation about reverting changes

rebase

public RebaseCommand rebase()
Returns a command object to execute a Rebase command

Returns:
a RebaseCommand used to collect all optional parameters and to finally execute the rebase command
See Also:
Git documentation about rebase

rm

public RmCommand rm()
Returns a command object to execute a rm command

Returns:
a RmCommand used to collect all optional parameters and to finally execute the rm command
See Also:
Git documentation about rm

checkout

public CheckoutCommand checkout()
Returns a command object to execute a checkout command

Returns:
a CheckoutCommand used to collect all optional parameters and to finally execute the checkout command
See Also:
Git documentation about checkout

reset

public ResetCommand reset()
Returns a command object to execute a reset command

Returns:
a ResetCommand used to collect all optional parameters and to finally execute the reset command
See Also:
Git documentation about reset

status

public StatusCommand status()
Returns a command object to execute a status command

Returns:
a StatusCommand used to collect all optional parameters and to finally execute the status command
See Also:
Git documentation about status

notesAdd

public AddNoteCommand notesAdd()
Returns a command to add notes to an object

Returns:
a AddNoteCommand

notesRemove

public RemoveNoteCommand notesRemove()
Returns a command to remove notes on an object

Returns:
a RemoveNoteCommand

notesList

public ListNotesCommand notesList()
Returns a command to list all notes

Returns:
a ListNotesCommand

notesShow

public ShowNoteCommand notesShow()
Returns a command to show notes on an object

Returns:
a ShowNoteCommand

lsRemote

public LsRemoteCommand lsRemote()
Returns a command object to execute a ls-remote command

Returns:
a LsRemoteCommand used to collect all optional parameters and to finally execute the status command
See Also:
Git documentation about ls-remote

clean

public CleanCommand clean()
Returns a command object to execute a clean command

Returns:
a CleanCommand used to collect all optional parameters and to finally execute the clean command
See Also:
Git documentation about Clean

blame

public BlameCommand blame()
Returns a command object to execute a blame command

Returns:
a BlameCommand used to collect all optional parameters and to finally execute the blame command
See Also:
Git documentation about Blame

reflog

public ReflogCommand reflog()
Returns a command object to execute a reflog command

Returns:
a ReflogCommand used to collect all optional parameters and to finally execute the reflog command
See Also:
Git documentation about reflog

diff

public DiffCommand diff()
Returns a command object to execute a diff command

Returns:
a DiffCommand used to collect all optional parameters and to finally execute the diff command
See Also:
Git documentation about diff

tagDelete

public DeleteTagCommand tagDelete()
Returns a command object used to delete tags

Returns:
a DeleteTagCommand

submoduleAdd

public SubmoduleAddCommand submoduleAdd()
Returns a command object to execute a submodule add command

Returns:
a SubmoduleAddCommand used to add a new submodule to a parent repository

submoduleInit

public SubmoduleInitCommand submoduleInit()
Returns a command object to execute a submodule init command

Returns:
a SubmoduleInitCommand used to initialize the repository's config with settings from the .gitmodules file in the working tree

submoduleStatus

public SubmoduleStatusCommand submoduleStatus()
Returns a command object to execute a submodule status command

Returns:
a SubmoduleStatusCommand used to report the status of a repository's configured submodules

submoduleSync

public SubmoduleSyncCommand submoduleSync()
Returns a command object to execute a submodule sync command

Returns:
a SubmoduleSyncCommand used to update the URL of a submodule from the parent repository's .gitmodules file

submoduleUpdate

public SubmoduleUpdateCommand submoduleUpdate()
Returns a command object to execute a submodule update command

Returns:
a SubmoduleUpdateCommand used to update the submodules in a repository to the configured revision

stashList

public StashListCommand stashList()
Returns a command object used to list stashed commits

Returns:
a StashListCommand

stashCreate

public StashCreateCommand stashCreate()
Returns a command object used to create a stashed commit

Returns:
a StashCreateCommand
Since:
2.0

stashApply

public StashApplyCommand stashApply()
Returns a command object used to apply a stashed commit

Returns:
a StashApplyCommand
Since:
2.0

stashDrop

public StashDropCommand stashDrop()
Returns a command object used to drop a stashed commit

Returns:
a StashDropCommand
Since:
2.0

apply

public ApplyCommand apply()
Returns a command object to execute a apply command

Returns:
a ApplyCommand used to collect all optional parameters and to finally execute the apply command
Since:
2.0
See Also:
Git documentation about apply

gc

public GarbageCollectCommand gc()
Returns a command object to execute a gc command

Returns:
a GarbageCollectCommand used to collect all optional parameters and to finally execute the gc command
Since:
2.2
See Also:
Git documentation about gc

getRepository

public Repository getRepository()
Returns:
the git repository this class is interacting with


Copyright © 2013. All Rights Reserved.