public class CheckoutCommand extends GitCommand<Ref>
Examples (git
is a Git
instance):
Check out an existing branch:
git.checkout().setName("feature").call();
Check out paths from the index:
git.checkout().addPath("file1.txt").addPath("file2.txt").call();
Check out a path from a commit:
git.checkout().setStartPoint("HEADˆ").addPath("file1.txt").call();
Create a new branch and check it out:
git.checkout().setCreateBranch(true).setName("newbranch").call();
Create a new tracking branch for a remote branch and check it out:
git.checkout().setCreateBranch(true).setName("stable") .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM) .setStartPoint("origin/stable").call();
Modifier and Type | Class and Description |
---|---|
static class |
CheckoutCommand.Stage
Stage to check out, see
setStage(Stage) . |
repo
Modifier | Constructor and Description |
---|---|
protected |
CheckoutCommand(Repository repo)
Constructor for CheckoutCommand
|
Modifier and Type | Method and Description |
---|---|
CheckoutCommand |
addPath(String path)
Add a single slash-separated path to the list of paths to check out.
|
CheckoutCommand |
addPaths(List<String> p)
Add multiple slash-separated paths to the list of paths to check out.
|
Ref |
call() |
protected CheckoutCommand |
checkoutPaths()
Checkout paths into index and working directory, firing a
WorkingTreeModifiedEvent if the working
tree was modified. |
CheckoutResult |
getResult()
Get the result, never
null |
CheckoutCommand |
setAllPaths(boolean all)
Set whether to checkout all paths.
|
CheckoutCommand |
setCreateBranch(boolean createBranch)
Specify whether to create a new branch.
|
CheckoutCommand |
setForce(boolean force)
Specify to force the ref update in case of a branch switch.
|
CheckoutCommand |
setName(String name)
Specify the name of the branch or commit to check out, or the new branch
name.
|
CheckoutCommand |
setOrphan(boolean orphan)
Specify whether to create a new orphan branch.
|
CheckoutCommand |
setProgressMonitor(ProgressMonitor monitor) |
CheckoutCommand |
setStage(CheckoutCommand.Stage stage)
When checking out the index, check out the specified stage (ours or
theirs) for unmerged paths.
|
CheckoutCommand |
setStartPoint(RevCommit startCommit)
Set the commit that should be checked out.
|
CheckoutCommand |
setStartPoint(String startPoint)
Set the name of the commit that should be checked out.
|
CheckoutCommand |
setUpstreamMode(CreateBranchCommand.SetupUpstreamMode mode)
When creating a branch with
setCreateBranch(boolean) , this can
be used to configure branch tracking. |
checkCallable, getRepository, setCallable
protected CheckoutCommand(Repository repo)
repo
- the Repository
public Ref call() throws GitAPIException, RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException, CheckoutConflictException
Execute the command
call
in interface Callable<Ref>
call
in class GitCommand<Ref>
GitAPIException
RefAlreadyExistsException
RefNotFoundException
InvalidRefNameException
CheckoutConflictException
public CheckoutCommand setProgressMonitor(ProgressMonitor monitor)
monitor
- a progress monitorpublic CheckoutCommand addPath(String path)
setAllPaths(boolean)
.
If this option is set, neither the setCreateBranch(boolean)
nor
setName(String)
option is considered. In other words, these
options are exclusive.
path
- path to update in the working tree and index (with
/
as separator)this
public CheckoutCommand addPaths(List<String> p)
setAllPaths(boolean)
.
If this option is set, neither the setCreateBranch(boolean)
nor
setName(String)
option is considered. In other words, these
options are exclusive.
p
- paths to update in the working tree and index (with
/
as separator)this
public CheckoutCommand setAllPaths(boolean all)
This options should be used when you want to do a path checkout on the
entire repository and so calling addPath(String)
is not possible
since empty paths are not allowed.
If this option is set, neither the setCreateBranch(boolean)
nor
setName(String)
option is considered. In other words, these
options are exclusive.
all
- true
to checkout all paths, false
otherwisethis
protected CheckoutCommand checkoutPaths() throws IOException, RefNotFoundException
WorkingTreeModifiedEvent
if the working
tree was modified.IOException
RefNotFoundException
public CheckoutCommand setName(String name)
When only checking out paths and not switching branches, use
setStartPoint(String)
or setStartPoint(RevCommit)
to
specify from which branch or commit to check out files.
When setCreateBranch(boolean)
is set to true
, use
this method to set the name of the new branch to create and
setStartPoint(String)
or setStartPoint(RevCommit)
to
specify the start point of the branch.
name
- the name of the branch or commitpublic CheckoutCommand setCreateBranch(boolean createBranch)
If true
is used, the name of the new branch must be set
using setName(String)
. The commit at which to start the new
branch can be set using setStartPoint(String)
or
setStartPoint(RevCommit)
; if not specified, HEAD is used. Also
see setUpstreamMode(org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode)
for setting up branch tracking.
createBranch
- if true
a branch will be created as part of the
checkout and set to the specified start pointpublic CheckoutCommand setOrphan(boolean orphan)
If true
is used, the name of the new orphan branch must be
set using setName(String)
. The commit at which to start the new
orphan branch can be set using setStartPoint(String)
or
setStartPoint(RevCommit)
; if not specified, HEAD is used.
orphan
- if true
a orphan branch will be created as part
of the checkout to the specified start pointpublic CheckoutCommand setForce(boolean force)
force
- if true
and the branch with the given name
already exists, the start-point of an existing branch will be
set to a new start-point; if false, the existing branch will
not be changedpublic CheckoutCommand setStartPoint(String startPoint)
When checking out files and this is not specified or null
,
the index is used.
When creating a new branch, this will be used as the start point. If not
specified or null
, the current HEAD is used.
startPoint
- commit name to check outpublic CheckoutCommand setStartPoint(RevCommit startCommit)
When creating a new branch, this will be used as the start point. If not
specified or null
, the current HEAD is used.
When checking out files and this is not specified or null
,
the index is used.
startCommit
- commit to check outpublic CheckoutCommand setUpstreamMode(CreateBranchCommand.SetupUpstreamMode mode)
setCreateBranch(boolean)
, this can
be used to configure branch tracking.mode
- corresponds to the --track/--no-track options; may be
null
public CheckoutCommand setStage(CheckoutCommand.Stage stage)
This can not be used when checking out a branch, only when checking out the index.
stage
- the stage to check outpublic CheckoutResult getResult()
null
null
Copyright © 2018 Eclipse JGit Project. All rights reserved.