Skip to content

Commit f496b06

Browse files
committed
Merge branch 'nd/switch-and-restore'
Two new commands "git switch" and "git restore" are introduced to split "checking out a branch to work on advancing its history" and "checking out paths out of the index and/or a tree-ish to work on advancing the current history" out of the single "git checkout" command. * nd/switch-and-restore: (46 commits) completion: disable dwim on "git switch -d" switch: allow to switch in the middle of bisect t2027: use test_must_be_empty Declare both git-switch and git-restore experimental help: move git-diff and git-reset to different groups doc: promote "git restore" user-manual.txt: prefer 'merge --abort' over 'reset --hard' completion: support restore t: add tests for restore restore: support --patch restore: replace --force with --ignore-unmerged restore: default to --source=HEAD when only --staged is specified restore: reject invalid combinations with --staged restore: add --worktree and --staged checkout: factor out worktree checkout code restore: disable overlay mode by default restore: make pathspec mandatory restore: take tree-ish from --source option instead checkout: split part of it to new command 'restore' doc: promote "git switch" ...
2 parents b49d337 + 97ed685 commit f496b06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1917
-661
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
/git-request-pull
140140
/git-rerere
141141
/git-reset
142+
/git-restore
142143
/git-rev-list
143144
/git-rev-parse
144145
/git-revert
@@ -163,6 +164,7 @@
163164
/git-submodule
164165
/git-submodule--helper
165166
/git-svn
167+
/git-switch
166168
/git-symbolic-ref
167169
/git-tag
168170
/git-unpack-file

Documentation/config/advice.txt

+8-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ advice.*::
4242
state in the output of linkgit:git-status[1], in
4343
the template shown when writing commit messages in
4444
linkgit:git-commit[1], and in the help message shown
45-
by linkgit:git-checkout[1] when switching branch.
45+
by linkgit:git-switch[1] or
46+
linkgit:git-checkout[1] when switching branch.
4647
statusUoption::
4748
Advise to consider using the `-u` option to linkgit:git-status[1]
4849
when the command takes more than 2 seconds to enumerate untracked
@@ -62,12 +63,14 @@ advice.*::
6263
your information is guessed from the system username and
6364
domain name.
6465
detachedHead::
65-
Advice shown when you used linkgit:git-checkout[1] to
66-
move to the detach HEAD state, to instruct how to create
67-
a local branch after the fact.
66+
Advice shown when you used
67+
linkgit:git-switch[1] or linkgit:git-checkout[1]
68+
to move to the detach HEAD state, to instruct how to
69+
create a local branch after the fact.
6870
checkoutAmbiguousRemoteBranchName::
6971
Advice shown when the argument to
70-
linkgit:git-checkout[1] ambiguously resolves to a
72+
linkgit:git-checkout[1] and linkgit:git-switch[1]
73+
ambiguously resolves to a
7174
remote tracking branch on more than one remote in
7275
situations where an unambiguous argument would have
7376
otherwise caused a remote-tracking branch to be

Documentation/config/branch.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
branch.autoSetupMerge::
2-
Tells 'git branch' and 'git checkout' to set up new branches
2+
Tells 'git branch', 'git switch' and 'git checkout' to set up new branches
33
so that linkgit:git-pull[1] will appropriately merge from the
44
starting point branch. Note that even if this option is not set,
55
this behavior can be chosen per-branch using the `--track`
@@ -11,7 +11,7 @@ branch.autoSetupMerge::
1111
branch. This option defaults to true.
1212

1313
branch.autoSetupRebase::
14-
When a new branch is created with 'git branch' or 'git checkout'
14+
When a new branch is created with 'git branch', 'git switch' or 'git checkout'
1515
that tracks another branch, this variable tells Git to set
1616
up pull to rebase instead of merge (see "branch.<name>.rebase").
1717
When `never`, rebase is never automatically set to true.

Documentation/config/checkout.txt

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
checkout.defaultRemote::
2-
When you run 'git checkout <something>' and only have one
2+
When you run 'git checkout <something>'
3+
or 'git switch <something>' and only have one
34
remote, it may implicitly fall back on checking out and
45
tracking e.g. 'origin/<something>'. This stops working as soon
56
as you have more than one remote with a '<something>'
@@ -8,16 +9,10 @@ checkout.defaultRemote::
89
disambiguation. The typical use-case is to set this to
910
`origin`.
1011
+
11-
Currently this is used by linkgit:git-checkout[1] when 'git checkout
12-
<something>' will checkout the '<something>' branch on another remote,
12+
Currently this is used by linkgit:git-switch[1] and
13+
linkgit:git-checkout[1] when 'git checkout <something>'
14+
or 'git switch <something>'
15+
will checkout the '<something>' branch on another remote,
1316
and by linkgit:git-worktree[1] when 'git worktree add' refers to a
1417
remote branch. This setting might be used for other checkout-like
1518
commands or functionality in the future.
16-
17-
checkout.optimizeNewBranch::
18-
Optimizes the performance of "git checkout -b <new_branch>" when
19-
using sparse-checkout. When set to true, git will not update the
20-
repo based on the current sparse-checkout settings. This means it
21-
will not update the skip-worktree bit in the index nor add/remove
22-
files in the working directory to reflect the current sparse checkout
23-
settings nor will it show the local changes.

Documentation/config/diff.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ diff.external::
7878
diff.ignoreSubmodules::
7979
Sets the default value of --ignore-submodules. Note that this
8080
affects only 'git diff' Porcelain, and not lower level 'diff'
81-
commands such as 'git diff-files'. 'git checkout' also honors
81+
commands such as 'git diff-files'. 'git checkout'
82+
and 'git switch' also honor
8283
this setting when reporting uncommitted changes. Setting it to
8384
'all' disables the submodule summary normally shown by 'git commit'
8485
and 'git status' when `status.submoduleSummary` is set unless it is

Documentation/config/interactive.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ interactive.singleKey::
22
In interactive commands, allow the user to provide one-letter
33
input with a single key (i.e., without hitting enter).
44
Currently this is used by the `--patch` mode of
5-
linkgit:git-add[1], linkgit:git-checkout[1], linkgit:git-commit[1],
5+
linkgit:git-add[1], linkgit:git-checkout[1],
6+
linkgit:git-restore[1], linkgit:git-commit[1],
67
linkgit:git-reset[1], and linkgit:git-stash[1]. Note that this
78
setting is silently ignored if portable keystroke input
89
is not available; requires the Perl module Term::ReadKey.

Documentation/git-branch.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ can leave out at most one of `A` and `B`, in which case it defaults to
6060
`HEAD`.
6161

6262
Note that this will create the new branch, but it will not switch the
63-
working tree to it; use "git checkout <newbranch>" to switch to the
63+
working tree to it; use "git switch <newbranch>" to switch to the
6464
new branch.
6565

6666
When a local branch is started off a remote-tracking branch, Git sets up the
@@ -214,7 +214,7 @@ This option is only applicable in non-verbose mode.
214214
+
215215
This behavior is the default when the start point is a remote-tracking branch.
216216
Set the branch.autoSetupMerge configuration variable to `false` if you
217-
want `git checkout` and `git branch` to always behave as if `--no-track`
217+
want `git switch`, `git checkout` and `git branch` to always behave as if `--no-track`
218218
were given. Set it to `always` if you want this behavior when the
219219
start-point is either a local or remote-tracking branch.
220220

@@ -313,7 +313,7 @@ Start development from a known tag::
313313
$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
314314
$ cd my2.6
315315
$ git branch my2.6.14 v2.6.14 <1>
316-
$ git checkout my2.6.14
316+
$ git switch my2.6.14
317317
------------
318318
+
319319
<1> This step and the next one could be combined into a single step with
@@ -350,9 +350,9 @@ Patterns will normally need quoting.
350350
NOTES
351351
-----
352352

353-
If you are creating a branch that you want to checkout immediately, it is
354-
easier to use the git checkout command with its `-b` option to create
355-
a branch and check it out with a single command.
353+
If you are creating a branch that you want to switch to immediately,
354+
it is easier to use the "git switch" command with its `-c` option to
355+
do the same thing with a single command.
356356

357357
The options `--contains`, `--no-contains`, `--merged` and `--no-merged`
358358
serve four related but different purposes:

Documentation/git-check-ref-format.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ but it is explicitly forbidden at the beginning of a branch name).
8888
When run with `--branch` option in a repository, the input is first
8989
expanded for the ``previous checkout syntax''
9090
`@{-n}`. For example, `@{-1}` is a way to refer the last thing that
91-
was checked out using "git checkout" operation. This option should be
91+
was checked out using "git switch" or "git checkout" operation.
92+
This option should be
9293
used by porcelains to accept this syntax anywhere a branch name is
9394
expected, so they can act as if you typed the branch name. As an
9495
exception note that, the ``previous checkout operation'' might result

0 commit comments

Comments
 (0)