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 booleanprivate final RepositoryThe git repository this class is interacting with -
Constructor Summary
ConstructorsConstructorDescriptionGit(Repository repo) Construct a newGitobject which can interact with the specified git repository.Git(Repository repo, boolean closeRepo) -
Method Summary
Modifier and TypeMethodDescriptionadd()Return a command object to execute aAddcommandapply()Return a command object to execute aapplycommandarchive()Return a command to create an archive from a treeblame()Return a command object to execute ablamecommandReturn 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 acheckoutcommandReturn a command object to execute acherry-pickcommandclean()Return a command object to execute acleancommandstatic CloneCommandReturn a command object to execute aclonecommandvoidclose()commit()Return a command object to execute aCommitcommanddescribe()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 adiffcommandfetch()Return a command object to execute aFetchcommandgc()Return a command object to execute agccommandGet repositorystatic InitCommandinit()Return a command object to execute ainitcommandlog()Return a command object to execute aLogcommandlsRemote()Return a command object to execute als-remotecommandstatic LsRemoteCommandReturn a command to list remote branches/tags without a local repository.merge()Return a command object to execute aMergecommandnameRev()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 GitOpen repositorystatic GitOpen repositorypull()Return a command object to execute aPullcommandpush()Return a command object to execute aPushcommandrebase()Return a command object to execute aRebasecommandreflog()Return a command object to execute areflogcommandReturn 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 aresetcommandrevert()Return a command object to execute arevertcommandrm()Return a command object to execute armcommandstatic voidshutdown()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 astatuscommandReturn a command object to execute asubmodule addcommandReturns a command object to execute asubmodule deinitcommandReturn a command object to execute asubmodule initcommandReturns a command object to execute asubmodule statuscommandReturn a command object to execute asubmodule synccommandReturn a command object to execute asubmodule updatecommandtag()Return a command object to execute aTagcommandReturn 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 Gitwrap(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 newGitobject 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;nullis 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
Gitobject 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
Gitobject 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; seeRepositoryfor 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
Gitinstance anymore.- Specified by:
closein interfaceAutoCloseable- Since:
- 3.2
-
cloneRepository
Return a command object to execute aclonecommand- Returns:
- a
CloneCommandused to collect all optional parameters and to finally execute theclonecommand - 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 ainitcommand- Returns:
- a
InitCommandused to collect all optional parameters and to finally execute theinitcommand - 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 aCommitcommand- Returns:
- a
CommitCommandused to collect all optional parameters and to finally execute theCommitcommand - See Also:
-
log
Return a command object to execute aLogcommand- Returns:
- a
LogCommandused to collect all optional parameters and to finally execute theLogcommand - See Also:
-
merge
Return a command object to execute aMergecommand- Returns:
- a
MergeCommandused to collect all optional parameters and to finally execute theMergecommand - See Also:
-
pull
Return a command object to execute aPullcommand- 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 aAddcommand- Returns:
- a
AddCommandused to collect all optional parameters and to finally execute theAddcommand - See Also:
-
tag
Return a command object to execute aTagcommand- Returns:
- a
TagCommandused to collect all optional parameters and to finally execute theTagcommand - See Also:
-
fetch
Return a command object to execute aFetchcommand- Returns:
- a
FetchCommandused to collect all optional parameters and to finally execute theFetchcommand - See Also:
-
push
Return a command object to execute aPushcommand- Returns:
- a
PushCommandused to collect all optional parameters and to finally execute thePushcommand - See Also:
-
cherryPick
Return a command object to execute acherry-pickcommand- Returns:
- a
CherryPickCommandused to collect all optional parameters and to finally execute thecherry-pickcommand - See Also:
-
revert
Return a command object to execute arevertcommand- Returns:
- a
RevertCommandused to collect all optional parameters and to finally execute thecherry-pickcommand - See Also:
-
rebase
Return a command object to execute aRebasecommand- Returns:
- a
RebaseCommandused to collect all optional parameters and to finally execute therebasecommand - See Also:
-
rm
Return a command object to execute armcommand- Returns:
- a
RmCommandused to collect all optional parameters and to finally execute thermcommand - See Also:
-
checkout
Return a command object to execute acheckoutcommand- Returns:
- a
CheckoutCommandused to collect all optional parameters and to finally execute thecheckoutcommand - See Also:
-
reset
Return a command object to execute aresetcommand- Returns:
- a
ResetCommandused to collect all optional parameters and to finally execute theresetcommand - See Also:
-
status
Return a command object to execute astatuscommand- Returns:
- a
StatusCommandused to collect all optional parameters and to finally execute thestatuscommand - 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-remotecommand- Returns:
- a
LsRemoteCommandused to collect all optional parameters and to finally execute thestatuscommand - See Also:
-
clean
Return a command object to execute acleancommand- Returns:
- a
CleanCommandused to collect all optional parameters and to finally execute thecleancommand - See Also:
-
blame
Return a command object to execute ablamecommand- Returns:
- a
BlameCommandused to collect all optional parameters and to finally execute theblamecommand - See Also:
-
reflog
Return a command object to execute areflogcommand- Returns:
- a
ReflogCommandused to collect all optional parameters and to finally execute thereflogcommand - See Also:
-
diff
Return a command object to execute adiffcommand- Returns:
- a
DiffCommandused to collect all optional parameters and to finally execute thediffcommand - See Also:
-
tagDelete
Return a command object used to delete tags- Returns:
- a
DeleteTagCommand
-
submoduleAdd
Return a command object to execute asubmodule addcommand- Returns:
- a
SubmoduleAddCommandused to add a new submodule to a parent repository
-
submoduleInit
Return a command object to execute asubmodule initcommand- Returns:
- a
SubmoduleInitCommandused to initialize the repository's config with settings from the .gitmodules file in the working tree
-
submoduleDeinit
Returns a command object to execute asubmodule deinitcommand- Returns:
- a
SubmoduleDeinitCommandused to remove a submodule's working tree manifestation - Since:
- 4.10
-
submoduleStatus
Returns a command object to execute asubmodule statuscommand- Returns:
- a
SubmoduleStatusCommandused to report the status of a repository's configured submodules
-
submoduleSync
Return a command object to execute asubmodule synccommand- Returns:
- a
SubmoduleSyncCommandused to update the URL of a submodule from the parent repository's .gitmodules file
-
submoduleUpdate
Return a command object to execute asubmodule updatecommand- Returns:
- a
SubmoduleUpdateCommandused 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 aapplycommand- Returns:
- a
ApplyCommandused to collect all optional parameters and to finally execute theapplycommand - Since:
- 2.0
- See Also:
-
gc
Return a command object to execute agccommand- Returns:
- a
GarbageCollectCommandused to collect all optional parameters and to finally execute thegccommand - 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
-