public class Git extends Object implements AutoCloseable
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 and Description |
---|
Git(Repository repo)
Construct a new
Git object which can
interact with the specified git repository. |
Modifier and Type | Method and Description |
---|---|
AddCommand |
add()
Return a command object to execute a
Add command |
ApplyCommand |
apply()
Return a command object to execute a
apply command |
ArchiveCommand |
archive()
Return a command to create an archive from a tree
|
BlameCommand |
blame()
Return a command object to execute a
blame command |
CreateBranchCommand |
branchCreate()
Return a command object used to create branches
|
DeleteBranchCommand |
branchDelete()
Return a command object used to delete branches
|
ListBranchCommand |
branchList()
Return a command object used to list branches
|
RenameBranchCommand |
branchRename()
Return a command object used to rename branches
|
CheckoutCommand |
checkout()
Return a command object to execute a
checkout command |
CherryPickCommand |
cherryPick()
Return a command object to execute a
cherry-pick command |
CleanCommand |
clean()
Return a command object to execute a
clean command |
static CloneCommand |
cloneRepository()
Return a command object to execute a
clone command |
void |
close() |
CommitCommand |
commit()
Return a command object to execute a
Commit command |
DescribeCommand |
describe()
Return a command object to come up with a short name that describes a
commit in terms of the nearest git tag.
|
DiffCommand |
diff()
Return a command object to execute a
diff command |
FetchCommand |
fetch()
Return a command object to execute a
Fetch command |
GarbageCollectCommand |
gc()
Return a command object to execute a
gc command |
Repository |
getRepository()
Get repository
|
static InitCommand |
init()
Return a command object to execute a
init command |
LogCommand |
log()
Return a command object to execute a
Log command |
LsRemoteCommand |
lsRemote()
Return a command object to execute a
ls-remote command |
static LsRemoteCommand |
lsRemoteRepository()
Return a command to list remote branches/tags without a local repository.
|
MergeCommand |
merge()
Return a command object to execute a
Merge command |
NameRevCommand |
nameRev()
Return a command object to find human-readable names of revisions.
|
AddNoteCommand |
notesAdd()
Return a command to add notes to an object
|
ListNotesCommand |
notesList()
Return a command to list all notes
|
RemoveNoteCommand |
notesRemove()
Return a command to remove notes on an object
|
ShowNoteCommand |
notesShow()
Return a command to show notes on an object
|
static Git |
open(File dir)
Open repository
|
static Git |
open(File dir,
FS fs)
Open repository
|
PullCommand |
pull()
Return a command object to execute a
Pull command |
PushCommand |
push()
Return a command object to execute a
Push command |
RebaseCommand |
rebase()
Return a command object to execute a
Rebase command |
ReflogCommand |
reflog()
Return a command object to execute a
reflog command |
RemoteAddCommand |
remoteAdd()
Return a command used to add a new remote.
|
RemoteListCommand |
remoteList()
Return a command used to list the available remotes.
|
RemoteRemoveCommand |
remoteRemove()
Return a command used to remove an existing remote.
|
RemoteSetUrlCommand |
remoteSetUrl()
Return a command used to change the URL of an existing remote.
|
ResetCommand |
reset()
Return a command object to execute a
reset command |
RevertCommand |
revert()
Return a command object to execute a
revert command |
RmCommand |
rm()
Return a command object to execute a
rm command |
StashApplyCommand |
stashApply()
Returs a command object used to apply a stashed commit
|
StashCreateCommand |
stashCreate()
Return a command object used to create a stashed commit
|
StashDropCommand |
stashDrop()
Return a command object used to drop a stashed commit
|
StashListCommand |
stashList()
Return a command object used to list stashed commits
|
StatusCommand |
status()
Return a command object to execute a
status command |
SubmoduleAddCommand |
submoduleAdd()
Return a command object to execute a
submodule add command |
SubmoduleDeinitCommand |
submoduleDeinit()
Returns a command object to execute a
submodule deinit command |
SubmoduleInitCommand |
submoduleInit()
Return a command object to execute a
submodule init command |
SubmoduleStatusCommand |
submoduleStatus()
Returns a command object to execute a
submodule status command |
SubmoduleSyncCommand |
submoduleSync()
Return a command object to execute a
submodule sync command |
SubmoduleUpdateCommand |
submoduleUpdate()
Return a command object to execute a
submodule update command |
TagCommand |
tag()
Return a command object to execute a
Tag command |
DeleteTagCommand |
tagDelete()
Return a command object used to delete tags
|
ListTagCommand |
tagList()
Return a command object used to list tags
|
String |
toString() |
static Git |
wrap(Repository repo)
Wrap repository
|
public Git(Repository repo)
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.
The caller is responsible for closing the repository; close()
on
this instance does not close the repo.
repo
- the git repository this class is interacting with;
null
is not allowed.public static Git open(File dir) throws IOException
dir
- the repository to open. May be either the GIT_DIR, or the
working tree directory that contains .git
.Git
object for the existing git
repositoryIOException
public static Git open(File dir, FS fs) throws IOException
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.Git
object for the existing git
repository. Closing this instance will close the repo.IOException
public static Git wrap(Repository repo)
public void close()
Free resources associated with this instance.
If the repository was opened by a static factory method in this class,
then this method calls Repository.close()
on the underlying
repository instance. (Whether this actually releases underlying
resources, such as file handles, may vary; see Repository
for
more details.)
If the repository was created by a caller and passed into
Git(Repository)
or a static factory method in this class, then
this method does not call close on the underlying repository.
In all cases, after calling this method you should not use this
Git
instance anymore.
close
in interface AutoCloseable
public static CloneCommand cloneRepository()
clone
commandCloneCommand
used to collect all
optional parameters and to finally execute the clone
commandpublic static LsRemoteCommand lsRemoteRepository()
LsRemoteCommand
public static InitCommand init()
init
commandInitCommand
used to collect all
optional parameters and to finally execute the init
commandpublic CommitCommand commit()
Commit
commandCommitCommand
used to collect all
optional parameters and to finally execute the Commit
commandpublic LogCommand log()
Log
commandLogCommand
used to collect all
optional parameters and to finally execute the Log
commandpublic MergeCommand merge()
Merge
commandMergeCommand
used to collect all
optional parameters and to finally execute the Merge
commandpublic PullCommand pull()
Pull
commandPullCommand
public CreateBranchCommand branchCreate()
CreateBranchCommand
public DeleteBranchCommand branchDelete()
DeleteBranchCommand
public ListBranchCommand branchList()
ListBranchCommand
public ListTagCommand tagList()
ListTagCommand
public RenameBranchCommand branchRename()
RenameBranchCommand
public AddCommand add()
Add
commandAddCommand
used to collect all
optional parameters and to finally execute the Add
commandpublic TagCommand tag()
Tag
commandTagCommand
used to collect all
optional parameters and to finally execute the Tag
commandpublic FetchCommand fetch()
Fetch
commandFetchCommand
used to collect all
optional parameters and to finally execute the Fetch
commandpublic PushCommand push()
Push
commandPushCommand
used to collect all
optional parameters and to finally execute the Push
commandpublic CherryPickCommand cherryPick()
cherry-pick
commandCherryPickCommand
used to collect
all optional parameters and to finally execute the
cherry-pick
commandpublic RevertCommand revert()
revert
commandRevertCommand
used to collect all
optional parameters and to finally execute the
cherry-pick
commandpublic RebaseCommand rebase()
Rebase
commandRebaseCommand
used to collect all
optional parameters and to finally execute the rebase
commandpublic RmCommand rm()
rm
commandRmCommand
used to collect all
optional parameters and to finally execute the rm
commandpublic CheckoutCommand checkout()
checkout
commandCheckoutCommand
used to collect
all optional parameters and to finally execute the
checkout
commandpublic ResetCommand reset()
reset
commandResetCommand
used to collect all
optional parameters and to finally execute the reset
commandpublic StatusCommand status()
status
commandStatusCommand
used to collect all
optional parameters and to finally execute the status
commandpublic ArchiveCommand archive()
ArchiveCommand
public AddNoteCommand notesAdd()
AddNoteCommand
public RemoveNoteCommand notesRemove()
RemoveNoteCommand
public ListNotesCommand notesList()
ListNotesCommand
public ShowNoteCommand notesShow()
ShowNoteCommand
public LsRemoteCommand lsRemote()
ls-remote
commandLsRemoteCommand
used to collect
all optional parameters and to finally execute the status
commandpublic CleanCommand clean()
clean
commandCleanCommand
used to collect all
optional parameters and to finally execute the clean
commandpublic BlameCommand blame()
blame
commandBlameCommand
used to collect all
optional parameters and to finally execute the blame
commandpublic ReflogCommand reflog()
reflog
commandReflogCommand
used to collect all
optional parameters and to finally execute the reflog
commandpublic DiffCommand diff()
diff
commandDiffCommand
used to collect all
optional parameters and to finally execute the diff
commandpublic DeleteTagCommand tagDelete()
DeleteTagCommand
public SubmoduleAddCommand submoduleAdd()
submodule add
commandSubmoduleAddCommand
used to add a
new submodule to a parent repositorypublic SubmoduleInitCommand submoduleInit()
submodule init
commandSubmoduleInitCommand
used to
initialize the repository's config with settings from the
.gitmodules file in the working treepublic SubmoduleDeinitCommand submoduleDeinit()
submodule deinit
commandSubmoduleDeinitCommand
used to
remove a submodule's working tree manifestationpublic SubmoduleStatusCommand submoduleStatus()
submodule status
commandSubmoduleStatusCommand
used to
report the status of a repository's configured submodulespublic SubmoduleSyncCommand submoduleSync()
submodule sync
commandSubmoduleSyncCommand
used to
update the URL of a submodule from the parent repository's
.gitmodules filepublic SubmoduleUpdateCommand submoduleUpdate()
submodule update
commandSubmoduleUpdateCommand
used to
update the submodules in a repository to the configured revisionpublic StashListCommand stashList()
StashListCommand
public StashCreateCommand stashCreate()
StashCreateCommand
public StashApplyCommand stashApply()
StashApplyCommand
public StashDropCommand stashDrop()
StashDropCommand
public ApplyCommand apply()
apply
commandApplyCommand
used to collect all
optional parameters and to finally execute the apply
commandpublic GarbageCollectCommand gc()
gc
commandGarbageCollectCommand
used to
collect all optional parameters and to finally execute the
gc
commandpublic NameRevCommand nameRev()
NameRevCommand
.public DescribeCommand describe()
DescribeCommand
.public RemoteListCommand remoteList()
RemoteListCommand
public RemoteAddCommand remoteAdd()
RemoteAddCommand
public RemoteRemoveCommand remoteRemove()
RemoteRemoveCommand
public RemoteSetUrlCommand remoteSetUrl()
RemoteSetUrlCommand
public Repository getRepository()
close()
for notes on closing this repository.Copyright © 2019 Eclipse JGit Project. All rights reserved.