Examples (git is a org. 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 |
|---|---|
| public static enum | CheckoutCommand.
Stage to check out, see |
| Modifier and Type | Field and Description |
|---|---|
| private Set | |
| private boolean | |
| private CheckoutCommand. | |
| private boolean | |
| private boolean | |
| private boolean | |
| private ProgressMonitor | |
| private String | |
| private boolean | |
| private List | |
| private RevCommit | |
| private String | |
| private CheckoutResult | |
| private CreateBranchCommand. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public CheckoutCommand | |
| public CheckoutCommand | |
| public Ref | call()
Implements abstract org. Implements java. Computes a result, or throws an exception if unable to do so. |
| private void | |
| private void | checkoutPath(DirCacheEntry entry, ObjectReader reader, Checkout checkout, String path, DirCacheCheckout.
|
| protected CheckoutCommand | Returns: this instanceCheckout paths into index and working directory, firing a
|
| private void | |
| private void | |
| private String | |
| public CheckoutResult | |
| private String | |
| private ObjectId | |
| private boolean | |
| private void | |
| public CheckoutCommand | Returns: thistrue to checkout all paths, false
otherwiseSet whether to checkout all paths. |
| public CheckoutCommand | Returns: this instanceif createBranch)true a branch will be created as part of the
checkout and set to the specified start pointSpecify whether to create a new branch. |
| public CheckoutCommand | Returns: this instanceif set to forced)true then allow the checkout even if
workingtree or index doesn't match HEAD. Overwrite workingtree
files and index content with the new content in this case.Allow a checkout even if the workingtree or index differs from HEAD. |
| public CheckoutCommand | Returns: this instanceif forceRefUpdate)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 changedSpecify to force the ref update in case of a branch switch. |
| public CheckoutCommand | |
| public CheckoutCommand | Returns: this instanceif orphan)true a orphan branch will be created as part
of the checkout to the specified start pointSpecify whether to create a new orphan branch. |
| public CheckoutCommand | Returns: this instancea progress monitor monitor)Set progress monitor |
| public CheckoutCommand | Returns: thisthe stage to check out stageWhen checking out the index, check out the specified stage (ours or theirs) for unmerged paths. |
| public CheckoutCommand | Returns: this instancecommit name to check out startPoint)Set the name of the commit that should be checked out. |
| public CheckoutCommand | Returns: this instancecommit to check out startCommit)Set the commit that should be checked out. |
| public CheckoutCommand | Returns: this instancecorresponds to the --track/--no-track options; may be
modenullWhen creating a branch with |
| actuallyModifiedPaths | back to summary |
|---|---|
| private Set<String> actuallyModifiedPaths | |
| checkoutAllPaths | back to summary |
|---|---|
| private boolean checkoutAllPaths | |
| checkoutStage | back to summary |
|---|---|
| private CheckoutCommand. | |
| createBranch | back to summary |
|---|---|
| private boolean createBranch | |
| forced | back to summary |
|---|---|
| private boolean forced | |
| forceRefUpdate | back to summary |
|---|---|
| private boolean forceRefUpdate | |
| monitor | back to summary |
|---|---|
| private ProgressMonitor monitor | |
| name | back to summary |
|---|---|
| private String name | |
| orphan | back to summary |
|---|---|
| private boolean orphan | |
| paths | back to summary |
|---|---|
| private List<String> paths | |
| startCommit | back to summary |
|---|---|
| private RevCommit startCommit | |
| startPoint | back to summary |
|---|---|
| private String startPoint | |
| status | back to summary |
|---|---|
| private CheckoutResult status | |
| upstreamMode | back to summary |
|---|---|
| private CreateBranchCommand. | |
| CheckoutCommand | back to summary |
|---|---|
| protected CheckoutCommand(Repository repo) Constructor for CheckoutCommand
| |
| addPath | back to summary |
|---|---|
| public CheckoutCommand addPath(String path) Add a single slash-separated path to the list of paths to check out. To
check out all paths, use
If this option is set, neither the
| |
| addPaths | back to summary |
|---|---|
| public CheckoutCommand addPaths(List<String> p) Add multiple slash-separated paths to the list of paths to check out. To
check out all paths, use
If this option is set, neither the
| |
| call | back to summary |
|---|---|
| public Ref call() throws GitAPIException, RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException, CheckoutConflictException Implements abstract org. Implements java. Doc from org. Computes a result, or throws an exception if unable to do so. Execute the command
| |
| checkOptions | back to summary |
|---|---|
| private void checkOptions() | |
| checkoutPath | back to summary |
|---|---|
| private void checkoutPath(DirCacheEntry entry, ObjectReader reader, Checkout checkout, String path, DirCacheCheckout. | |
| checkoutPaths | back to summary |
|---|---|
| protected CheckoutCommand checkoutPaths() throws IOException, RefNotFoundException Checkout paths into index and working directory, firing a
| |
| checkoutPathsFromCommit | back to summary |
|---|---|
| private void checkoutPathsFromCommit(TreeWalk treeWalk, DirCache dc, RevCommit commit, Checkout checkout) throws IOException | |
| checkoutPathsFromIndex | back to summary |
|---|---|
| private void checkoutPathsFromIndex(TreeWalk treeWalk, DirCache dc, Checkout checkout) throws IOException | |
| getBranchName | back to summary |
|---|---|
| private String getBranchName() | |
| getResult | back to summary |
|---|---|
| public CheckoutResult getResult() Get the result, never
| |
| getShortBranchName | back to summary |
|---|---|
| private String getShortBranchName(Ref headRef) | |
| getStartPointObjectId | back to summary |
|---|---|
| private ObjectId getStartPointObjectId() throws AmbiguousObjectException, RefNotFoundException, IOException | |
| isCheckoutIndex | back to summary |
|---|---|
| private boolean isCheckoutIndex() | |
| processOptions | back to summary |
|---|---|
| private void processOptions() throws InvalidRefNameException, RefAlreadyExistsException, IOException | |
| setAllPaths | back to summary |
|---|---|
| public CheckoutCommand setAllPaths(boolean all) Set whether to checkout all paths.
This options should be used when you want to do a path checkout on the
entire repository and so calling
If this option is set, neither the
| |
| setCreateBranch | back to summary |
|---|---|
| public CheckoutCommand setCreateBranch(boolean createBranch) Specify whether to create a new branch.
If
| |
| setForced | back to summary |
|---|---|
| public CheckoutCommand setForced(boolean forced) Allow a checkout even if the workingtree or index differs from HEAD. This
matches native git's '--force' option.
JGit releases before 5.2 had a method
| |
| setForceRefUpdate | back to summary |
|---|---|
| public CheckoutCommand setForceRefUpdate(boolean forceRefUpdate) Specify to force the ref update in case of a branch switch. In releases prior to 5.2 this method was called setForce() but this name was misunderstood to implement native git's --force option, which is not true.
| |
| setName | back to summary |
|---|---|
| public CheckoutCommand setName(String name) Specify the name of the branch or commit to check out, or the new branch name.
When only checking out paths and not switching branches, use
When
| |
| setOrphan | back to summary |
|---|---|
| public CheckoutCommand setOrphan(boolean orphan) Specify whether to create a new orphan branch.
If
| |
| setProgressMonitor | back to summary |
|---|---|
| public CheckoutCommand setProgressMonitor(ProgressMonitor monitor) Set progress monitor
| |
| setStage | back to summary |
|---|---|
| public CheckoutCommand setStage(CheckoutCommand. When checking out the index, check out the specified stage (ours or theirs) for unmerged paths. This can not be used when checking out a branch, only when checking out the index.
| |
| setStartPoint | back to summary |
|---|---|
| public CheckoutCommand setStartPoint(String startPoint) Set the name of the commit that should be checked out.
When checking out files and this is not specified or
When creating a new branch, this will be used as the start point. If not
specified or
| |
| setStartPoint | back to summary |
|---|---|
| public CheckoutCommand setStartPoint(RevCommit startCommit) Set the commit that should be checked out.
When creating a new branch, this will be used as the start point. If not
specified or
When checking out files and this is not specified or
| |
| setUpstreamMode | back to summary |
|---|---|
| public CheckoutCommand setUpstreamMode(CreateBranchCommand. When creating a branch with
| |
CheckoutCommand#setStage(Stage).
| Modifier and Type | Field and Description |
|---|---|
| public static final CheckoutCommand. | BASE
Base stage (#1) |
| private final int | |
| public static final CheckoutCommand. | OURS
Ours stage (#2) |
| public static final CheckoutCommand. | THEIRS
Theirs stage (#3) |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static CheckoutCommand. | |
| public static CheckoutCommand. |
| BASE | back to summary |
|---|---|
| public static final CheckoutCommand. Base stage (#1) | |
| number | back to summary |
|---|---|
| private final int number | |
| OURS | back to summary |
|---|---|
| public static final CheckoutCommand. Ours stage (#2) | |
| THEIRS | back to summary |
|---|---|
| public static final CheckoutCommand. Theirs stage (#3) | |
| Stage | back to summary |
|---|---|
| private Stage(int number) | |
| valueOf | back to summary |
|---|---|
| public static CheckoutCommand. | |
| values | back to summary |
|---|---|
| public static CheckoutCommand. | |