Skip to content

Commit 80f537f

Browse files
pcloudsgitster
authored andcommitted
doc: promote "git restore"
The new command "git restore" (together with "git switch") are added to avoid the confusion of one-command-do-all "git checkout" for new users. They are also helpful to avoid ambiguous context. For these reasons, promote it everywhere possible. This includes documentation, suggestions/advice from other commands. One nice thing about git-restore is the ability to restore "everything", so it can be used in "git status" advice instead of both "git checkout" and "git reset". The three commands suggested by "git status" are add, rm and restore. "git checkout" is also removed from "git help" (i.e. it's no longer considered a commonly used command) Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fc991b4 commit 80f537f

16 files changed

+93
-84
lines changed

Documentation/git-clean.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ OPTIONS
6464
directory) and $GIT_DIR/info/exclude, but do still use the ignore
6565
rules given with `-e` options. This allows removing all untracked
6666
files, including build products. This can be used (possibly in
67-
conjunction with 'git reset') to create a pristine
67+
conjunction with 'git restore' or 'git reset') to create a pristine
6868
working directory to test a clean build.
6969

7070
-X::

Documentation/git-commit.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ When recording your own work, the contents of modified files in
359359
your working tree are temporarily stored to a staging area
360360
called the "index" with 'git add'. A file can be
361361
reverted back, only in the index but not in the working tree,
362-
to that of the last commit with `git reset HEAD -- <file>`,
362+
to that of the last commit with `git restore --staged <file>`,
363363
which effectively reverts 'git add' and prevents the changes to
364364
this file from participating in the next commit. After building
365365
the state to be committed incrementally with these commands,

Documentation/git-format-patch.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ One way to test if your MUA is set up correctly is:
422422

423423
$ git fetch <project> master:test-apply
424424
$ git switch test-apply
425-
$ git reset --hard
425+
$ git restore --source=HEAD --staged --worktree :/
426426
$ git am a.patch
427427

428428
If it does not apply correctly, there can be various reasons.

Documentation/git-reset.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ This means that `git reset <paths>` is the opposite of `git add
2929
`git restore [--source=<tree-ish>] --staged <paths>...`.
3030
+
3131
After running `git reset <paths>` to update the index entry, you can
32-
use linkgit:git-checkout[1] to check the contents out of the index to
33-
the working tree.
34-
Alternatively, using linkgit:git-checkout[1] and specifying a commit, you
32+
use linkgit:git-restore[1] to check the contents out of the index to
33+
the working tree. Alternatively, using linkgit:git-restore[1]
34+
and specifying a commit with `--source`, you
3535
can copy the contents of a path out of a commit to the index and to the
3636
working tree in one go.
3737

Documentation/git-revert.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ effect of some earlier commits (often only a faulty one). If you want to
2626
throw away all uncommitted changes in your working directory, you
2727
should see linkgit:git-reset[1], particularly the `--hard` option. If
2828
you want to extract specific files as they were in another commit, you
29-
should see linkgit:git-checkout[1], specifically the `git checkout
30-
<commit> -- <filename>` syntax. Take care with these alternatives as
29+
should see linkgit:git-restore[1], specifically the `--source`
30+
option. Take care with these alternatives as
3131
both will discard uncommitted changes in your working directory.
3232

3333
See "Reset, restore and revert" in linkgit:git[1] for the differences

Documentation/gitcli.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ disambiguating `--` at appropriate places.
4747
things:
4848
+
4949
--------------------------------
50-
$ git checkout -- *.c
51-
$ git checkout -- \*.c
50+
$ git restore *.c
51+
$ git restore \*.c
5252
--------------------------------
5353
+
5454
The former lets your shell expand the fileglob, and you are asking

Documentation/giteveryday.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ following commands.
5151

5252
* linkgit:git-commit[1] to advance the current branch.
5353

54-
* linkgit:git-reset[1] and linkgit:git-checkout[1] (with
55-
pathname parameters) to undo changes.
54+
* linkgit:git-restore[1] to undo changes.
5655

5756
* linkgit:git-merge[1] to merge between local branches.
5857

@@ -82,7 +81,7 @@ Create a topic branch and develop.::
8281
------------
8382
$ git switch -c alsa-audio <1>
8483
$ edit/compile/test
85-
$ git checkout -- curses/ux_audio_oss.c <2>
84+
$ git restore curses/ux_audio_oss.c <2>
8685
$ git add curses/ux_audio_alsa.c <3>
8786
$ edit/compile/test
8887
$ git diff HEAD <4>

Documentation/gittutorial-2.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,13 @@ situation:
370370
$ git status
371371
On branch master
372372
Changes to be committed:
373-
(use "git reset HEAD <file>..." to unstage)
373+
(use "git restore --staged <file>..." to unstage)
374374

375375
new file: closing.txt
376376

377377
Changes not staged for commit:
378378
(use "git add <file>..." to update what will be committed)
379-
(use "git checkout -- <file>..." to discard changes in working directory)
379+
(use "git restore <file>..." to discard changes in working directory)
380380

381381
modified: file.txt
382382

Documentation/gittutorial.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ $ git status
110110
On branch master
111111
Changes to be committed:
112112
Your branch is up to date with 'origin/master'.
113-
(use "git reset HEAD <file>..." to unstage)
113+
(use "git restore --staged <file>..." to unstage)
114114

115115
modified: file1
116116
modified: file2

Documentation/user-manual.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ mistake, you can return the entire working tree to the last committed
14461446
state with
14471447

14481448
-------------------------------------------------
1449-
$ git reset --hard HEAD
1449+
$ git restore --staged --worktree :/
14501450
-------------------------------------------------
14511451

14521452
If you make a commit that you later wish you hadn't, there are two
@@ -1523,12 +1523,10 @@ Checking out an old version of a file
15231523

15241524
In the process of undoing a previous bad change, you may find it
15251525
useful to check out an older version of a particular file using
1526-
linkgit:git-checkout[1]. We've used `git checkout` before to switch
1527-
branches, but it has quite different behavior if it is given a path
1528-
name: the command
1526+
linkgit:git-restore[1]. The command
15291527

15301528
-------------------------------------------------
1531-
$ git checkout HEAD^ path/to/file
1529+
$ git restore --source=HEAD^ path/to/file
15321530
-------------------------------------------------
15331531

15341532
replaces path/to/file by the contents it had in the commit HEAD^, and
@@ -3800,8 +3798,8 @@ use linkgit:git-tag[1] for both.
38003798
The Workflow
38013799
------------
38023800

3803-
High-level operations such as linkgit:git-commit[1],
3804-
linkgit:git-checkout[1] and linkgit:git-reset[1] work by moving data
3801+
High-level operations such as linkgit:git-commit[1] and
3802+
linkgit:git-restore[1] work by moving data
38053803
between the working tree, the index, and the object database. Git
38063804
provides low-level operations which perform each of these steps
38073805
individually.

0 commit comments

Comments
 (0)