Class Git
- All Implemented Interfaces:
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
private final Repository
The git repository this class is interacting with -
Constructor Summary
ConstructorsConstructorDescriptionGit
(Repository repo) Construct a newGit
object which can interact with the specified git repository.Git
(Repository repo, boolean closeRepo) -
Method Summary
Modifier and TypeMethodDescriptionadd()
Return a command object to execute aAdd
commandapply()
Return a command object to execute aapply
commandarchive()
Return a command to create an archive from a treeblame()
Return a command object to execute ablame
commandReturn a command object used to create branchesReturn a command object used to delete branchesReturn a command object used to list branchesReturn a command object used to rename branchescheckout()
Return a command object to execute acheckout
commandReturn a command object to execute acherry-pick
commandclean()
Return a command object to execute aclean
commandstatic CloneCommand
Return a command object to execute aclone
commandvoid
close()
commit()
Return a command object to execute aCommit
commanddescribe()
Return a command object to come up with a short name that describes a commit in terms of the nearest git tag.diff()
Return a command object to execute adiff
commandfetch()
Return a command object to execute aFetch
commandgc()
Return a command object to execute agc
commandGet repositorystatic InitCommand
init()
Return a command object to execute ainit
commandlog()
Return a command object to execute aLog
commandlsRemote()
Return a command object to execute als-remote
commandstatic LsRemoteCommand
Return a command to list remote branches/tags without a local repository.merge()
Return a command object to execute aMerge
commandnameRev()
Return a command object to find human-readable names of revisions.notesAdd()
Return a command to add notes to an objectReturn a command to list all notesReturn a command to remove notes on an objectReturn a command to show notes on an objectstatic Git
Open repositorystatic Git
Open repositorypull()
Return a command object to execute aPull
commandpush()
Return a command object to execute aPush
commandrebase()
Return a command object to execute aRebase
commandreflog()
Return a command object to execute areflog
commandReturn a command used to add a new remote.Return a command used to list the available remotes.Return a command used to remove an existing remote.Return a command used to change the URL of an existing remote.reset()
Return a command object to execute areset
commandrevert()
Return a command object to execute arevert
commandrm()
Return a command object to execute arm
commandstatic void
shutdown()
Shutdown JGit and release resources it holds like NLS and thread poolsReturs a command object used to apply a stashed commitReturn a command object used to create a stashed commitReturn a command object used to drop a stashed commitReturn a command object used to list stashed commitsstatus()
Return a command object to execute astatus
commandReturn a command object to execute asubmodule add
commandReturns a command object to execute asubmodule deinit
commandReturn a command object to execute asubmodule init
commandReturns a command object to execute asubmodule status
commandReturn a command object to execute asubmodule sync
commandReturn a command object to execute asubmodule update
commandtag()
Return a command object to execute aTag
commandReturn a command object used to delete tagstagList()
Return a command object used to list tagstoString()
Return a command to verify signatures of tags or commits.static Git
wrap
(Repository repo) Wrap repository
-
Field Details
-
repo
The git repository this class is interacting with -
closeRepo
private final boolean closeRepo
-
-
Constructor Details
-
Git
Construct a newGit
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.- Parameters:
repo
- the git repository this class is interacting with;null
is not allowed.
-
Git
Git(Repository repo, boolean closeRepo)
-
-
Method Details
-
open
Open repository- 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
Open repository- 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. Closing this instance will close the repo. - Throws:
IOException
-
wrap
Wrap repository -
close
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; seeRepository
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.- Specified by:
close
in interfaceAutoCloseable
- Since:
- 3.2
-
cloneRepository
Return a command object to execute aclone
command- Returns:
- a
CloneCommand
used to collect all optional parameters and to finally execute theclone
command - See Also:
-
lsRemoteRepository
Return a command to list remote branches/tags without a local repository.- Returns:
- a
LsRemoteCommand
- Since:
- 3.1
-
init
Return a command object to execute ainit
command- Returns:
- a
InitCommand
used to collect all optional parameters and to finally execute theinit
command - See Also:
-
shutdown
public static void shutdown()Shutdown JGit and release resources it holds like NLS and thread pools- Since:
- 5.8
-
commit
Return a command object to execute aCommit
command- Returns:
- a
CommitCommand
used to collect all optional parameters and to finally execute theCommit
command - See Also:
-
log
Return a command object to execute aLog
command- Returns:
- a
LogCommand
used to collect all optional parameters and to finally execute theLog
command - See Also:
-
merge
Return a command object to execute aMerge
command- Returns:
- a
MergeCommand
used to collect all optional parameters and to finally execute theMerge
command - See Also:
-
pull
Return a command object to execute aPull
command- Returns:
- a
PullCommand
-
branchCreate
Return a command object used to create branches- Returns:
- a
CreateBranchCommand
-
branchDelete
Return a command object used to delete branches- Returns:
- a
DeleteBranchCommand
-
branchList
Return a command object used to list branches- Returns:
- a
ListBranchCommand
-
tagList
Return a command object used to list tags- Returns:
- a
ListTagCommand
-
branchRename
Return a command object used to rename branches- Returns:
- a
RenameBranchCommand
-
add
Return a command object to execute aAdd
command- Returns:
- a
AddCommand
used to collect all optional parameters and to finally execute theAdd
command - See Also:
-
tag
Return a command object to execute aTag
command- Returns:
- a
TagCommand
used to collect all optional parameters and to finally execute theTag
command - See Also:
-
fetch
Return a command object to execute aFetch
command- Returns:
- a
FetchCommand
used to collect all optional parameters and to finally execute theFetch
command - See Also:
-
push
Return a command object to execute aPush
command- Returns:
- a
PushCommand
used to collect all optional parameters and to finally execute thePush
command - See Also:
-
cherryPick
Return a command object to execute acherry-pick
command- Returns:
- a
CherryPickCommand
used to collect all optional parameters and to finally execute thecherry-pick
command - See Also:
-
revert
Return a command object to execute arevert
command- Returns:
- a
RevertCommand
used to collect all optional parameters and to finally execute thecherry-pick
command - See Also:
-
rebase
Return a command object to execute aRebase
command- Returns:
- a
RebaseCommand
used to collect all optional parameters and to finally execute therebase
command - See Also:
-
rm
Return a command object to execute arm
command- Returns:
- a
RmCommand
used to collect all optional parameters and to finally execute therm
command - See Also:
-
checkout
Return a command object to execute acheckout
command- Returns:
- a
CheckoutCommand
used to collect all optional parameters and to finally execute thecheckout
command - See Also:
-
reset
Return a command object to execute areset
command- Returns:
- a
ResetCommand
used to collect all optional parameters and to finally execute thereset
command - See Also:
-
status
Return a command object to execute astatus
command- Returns:
- a
StatusCommand
used to collect all optional parameters and to finally execute thestatus
command - See Also:
-
archive
Return a command to create an archive from a tree- Returns:
- a
ArchiveCommand
- Since:
- 3.1
-
notesAdd
Return a command to add notes to an object- Returns:
- a
AddNoteCommand
-
notesRemove
Return a command to remove notes on an object- Returns:
- a
RemoveNoteCommand
-
notesList
Return a command to list all notes- Returns:
- a
ListNotesCommand
-
notesShow
Return a command to show notes on an object- Returns:
- a
ShowNoteCommand
-
lsRemote
Return a command object to execute als-remote
command- Returns:
- a
LsRemoteCommand
used to collect all optional parameters and to finally execute thestatus
command - See Also:
-
clean
Return a command object to execute aclean
command- Returns:
- a
CleanCommand
used to collect all optional parameters and to finally execute theclean
command - See Also:
-
blame
Return a command object to execute ablame
command- Returns:
- a
BlameCommand
used to collect all optional parameters and to finally execute theblame
command - See Also:
-
reflog
Return a command object to execute areflog
command- Returns:
- a
ReflogCommand
used to collect all optional parameters and to finally execute thereflog
command - See Also:
-
diff
Return a command object to execute adiff
command- Returns:
- a
DiffCommand
used to collect all optional parameters and to finally execute thediff
command - See Also:
-
tagDelete
Return a command object used to delete tags- Returns:
- a
DeleteTagCommand
-
submoduleAdd
Return a command object to execute asubmodule add
command- Returns:
- a
SubmoduleAddCommand
used to add a new submodule to a parent repository
-
submoduleInit
Return a command object to execute asubmodule init
command- Returns:
- a
SubmoduleInitCommand
used to initialize the repository's config with settings from the .gitmodules file in the working tree
-
submoduleDeinit
Returns a command object to execute asubmodule deinit
command- Returns:
- a
SubmoduleDeinitCommand
used to remove a submodule's working tree manifestation - Since:
- 4.10
-
submoduleStatus
Returns a command object to execute asubmodule status
command- Returns:
- a
SubmoduleStatusCommand
used to report the status of a repository's configured submodules
-
submoduleSync
Return a command object to execute asubmodule sync
command- Returns:
- a
SubmoduleSyncCommand
used to update the URL of a submodule from the parent repository's .gitmodules file
-
submoduleUpdate
Return a command object to execute asubmodule update
command- Returns:
- a
SubmoduleUpdateCommand
used to update the submodules in a repository to the configured revision
-
stashList
Return a command object used to list stashed commits- Returns:
- a
StashListCommand
-
stashCreate
Return a command object used to create a stashed commit- Returns:
- a
StashCreateCommand
- Since:
- 2.0
-
stashApply
Returs a command object used to apply a stashed commit- Returns:
- a
StashApplyCommand
- Since:
- 2.0
-
stashDrop
Return a command object used to drop a stashed commit- Returns:
- a
StashDropCommand
- Since:
- 2.0
-
apply
Return a command object to execute aapply
command- Returns:
- a
ApplyCommand
used to collect all optional parameters and to finally execute theapply
command - Since:
- 2.0
- See Also:
-
gc
Return a command object to execute agc
command- Returns:
- a
GarbageCollectCommand
used to collect all optional parameters and to finally execute thegc
command - Since:
- 2.2
- See Also:
-
nameRev
Return a command object to find human-readable names of revisions.- Returns:
- a
NameRevCommand
. - Since:
- 3.0
-
describe
Return a command object to come up with a short name that describes a commit in terms of the nearest git tag.- Returns:
- a
DescribeCommand
. - Since:
- 3.2
-
remoteList
Return a command used to list the available remotes.- Returns:
- a
RemoteListCommand
- Since:
- 4.2
-
remoteAdd
Return a command used to add a new remote.- Returns:
- a
RemoteAddCommand
- Since:
- 4.2
-
remoteRemove
Return a command used to remove an existing remote.- Returns:
- a
RemoteRemoveCommand
- Since:
- 4.2
-
remoteSetUrl
Return a command used to change the URL of an existing remote.- Returns:
- a
RemoteSetUrlCommand
- Since:
- 4.2
-
verifySignature
Return a command to verify signatures of tags or commits.- Returns:
- a
VerifySignatureCommand
- Since:
- 5.11
-
getRepository
Get repository- Returns:
- the git repository this class is interacting with; see
close()
for notes on closing this repository.
-
toString
-