From: Nguyễn Thái Ngọc Duy Date: Thu, 11 Apr 2019 13:12:02 GMT Subject: [PATCH v2 00/16] Add new command 'restore' Message-ID: <20190411131218.19195-1-pclouds@gmail.com> In-Reply-To: <20190308101655.9767-1-pclouds@gmail.com> This is the companion of "git switch" and is based on that topic. This command peforms the "checkout paths" from git-checkout, git-reset and also has a third mode to reset only worktree, leaving the index alone. For new people not aware of previous discussions, this command is supposed to be a friendlier replacement for "git checkout" and hopefully fixes some warts that have grown over the time in git-checkout. For this reason, the last patch starts to recommend "git restore" everywhere. v2 should address all the comments from v1. I still haven't done that --intent-to-add thing yet even though I'd like to make it default behavior too. Anyway changes are - --index is renamed to --staged to avoid conflict with --index from git-apply, which has different meaning. - lots of document fixes. The comparison between restore/revert/reset is added in git.txt instead. I want to avoid duplicate the same thing on three man pages. - --force is dropped. --ignore-unmerged takes its place. - --recurse-submodules is dropped. I've concluded that restoring files across submodule boundary is not exactly supported yet. Let's leave it for later. - git-rm learns about --staged as an alias of --cached (in fact it's more the other way around). This is to keep suggestions consistent because we tell people to do "git foo --staged" everywhere. - git-reset and git-diff are moved to other groups in "git help" output. Nguyễn Thái Ngọc Duy (16): checkout: split part of it to new command 'restore' restore: take tree-ish from --source option instead restore: make pathspec mandatory restore: disable overlay mode by default checkout: factor out worktree checkout code restore: add --worktree and --staged restore: reject invalid combinations with --staged restore: default to --source=HEAD when only --staged is specified restore: replace --force with --ignore-unmerged restore: support --patch t: add tests for restore completion: support restore user-manual.txt: prefer 'merge --abort' over 'reset --hard' doc: promote "git restore" rm: add --staged as alias for --cached help: move git-diff and git-reset to different groups .gitignore | 1 + Documentation/config/interactive.txt | 3 +- Documentation/git-checkout.txt | 3 +- Documentation/git-clean.txt | 2 +- Documentation/git-commit.txt | 2 +- Documentation/git-format-patch.txt | 2 +- Documentation/git-reset.txt | 13 +- Documentation/git-restore.txt (new) | 183 +++++++++++++++ Documentation/git-revert.txt | 7 +- Documentation/git-rm.txt | 7 +- Documentation/git.txt | 20 ++ Documentation/gitcli.txt | 4 +- Documentation/giteveryday.txt | 5 +- Documentation/gittutorial-2.txt | 4 +- Documentation/gittutorial.txt | 2 +- Documentation/user-manual.txt | 14 +- Makefile | 1 + builtin.h | 1 + builtin/checkout.c | 299 +++++++++++++++++++------ builtin/clone.c | 2 +- builtin/commit.c | 2 +- builtin/rm.c | 7 +- command-list.txt | 7 +- contrib/completion/git-completion.bash | 15 ++ git-add--interactive.perl | 52 +++++ git.c | 1 + t/lib-patch-mode.sh | 12 + t/t2070-restore.sh (new +x) | 99 ++++++++ t/t2071-restore-patch.sh (new +x) | 110 +++++++++ t/t3600-rm.sh | 6 +- t/t7508-status.sh | 84 +++---- t/t7512-status-help.sh | 20 +- wt-status.c | 30 ++- 33 files changed, 848 insertions(+), 172 deletions(-) create mode 100644 Documentation/git-restore.txt create mode 100755 t/t2070-restore.sh create mode 100755 t/t2071-restore-patch.sh Diff: diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index ee0d164d0e..a294652dd6 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -570,7 +570,7 @@ $ git add frotz SEE ALSO -------- -linkgit:git-switch[1] +linkgit:git-switch[1], linkgit:git-restore[1] GIT diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index e7ac8eb9e8..7628193284 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -56,7 +56,7 @@ summary of what is included by any of the above for the next commit by giving the same set of parameters (options and paths). If you make a commit and then find a mistake immediately after -that, you can recover from it with 'git restore' or 'git reset'. +that, you can recover from it with 'git reset'. OPTIONS @@ -359,7 +359,7 @@ When recording your own work, the contents of modified files in your working tree are temporarily stored to a staging area called the "index" with 'git add'. A file can be reverted back, only in the index but not in the working tree, -to that of the last commit with `git restore --index `, +to that of the last commit with `git restore --staged `, which effectively reverts 'git add' and prevents the changes to this file from participating in the next commit. After building the state to be committed incrementally with these commands, diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 71c9fe3af3..01bfcecf69 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -422,7 +422,7 @@ One way to test if your MUA is set up correctly is: $ git fetch master:test-apply $ git switch test-apply - $ git restore --source=HEAD --index --worktree :/ + $ git restore --source=HEAD --staged --worktree :/ $ git am a.patch If it does not apply correctly, there can be various reasons. diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index b70281677f..633d71d36a 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -25,7 +25,8 @@ The ``/`` defaults to `HEAD` in all forms. the current branch.) + This means that `git reset ` is the opposite of `git add -`. +`. This command is equivalent to +`git restore [--source=] --staged ...`. + After running `git reset ` to update the index entry, you can use linkgit:git-restore[1] to check the contents out of the index to @@ -86,8 +87,8 @@ but carries forward unmerged index entries. changes, reset is aborted. -- -If you want to undo a commit other than the latest on a branch, -linkgit:git-revert[1] is your friend. +See "Reset, restore and revert" in linkgit:git[1] for the differences +between the three commands. OPTIONS diff --git a/Documentation/git-restore.txt b/Documentation/git-restore.txt index a667a5ced4..b608f3f360 100644 --- a/Documentation/git-restore.txt +++ b/Documentation/git-restore.txt @@ -8,48 +8,60 @@ git-restore - Restore working tree files SYNOPSIS -------- [verse] -'git restore' [] [--source=] ... -'git restore' (-p|--patch) [--source=] [...] +'git restore' [] [--source=] [--staged] [--worktree] ... +'git restore' (-p|--patch) [] [--source=] [--staged] [--worktree] [...] DESCRIPTION ----------- -Restore paths in the working tree by replacing with the contents in -the restore source or remove if the paths do not exist in the restore -source. The source is by default the index but could be from a commit. -The command can also optionally restore content in the index from a -commit. +Restore specified paths in the working tree with some contents from a +restore source. If a path is tracked but does not exist in the restore +source, it will be removed to match the source. -When a `` is given, the paths that match the `` are -updated both in the index and in the working tree. +The command can also be used to restore the content in the index with +`--staged`, or restore both the working tree and the index with +`--staged --worktree`. + +By default, the restore sources for working tree and the index are the +index and `HEAD` respectively. `--source` could be used to specify a +commit as the restore source. + +See "Reset, restore and revert" in linkgit:git[1] for the differences +between the three commands. OPTIONS ------- --s:: +-s :: --source=:: Restore the working tree files with the content from the given - tree or any revision that leads to a tree (e.g. a commit or a - branch). + tree. It is common to specify the source tree by naming a + commit, branch or tag associated with it. ++ +If not specified, the default restore source for the working tree is +the index, and the default restore source for the index index is +`HEAD`. When both `--staged` and `--worktree` are specified, +`--source` must also be specified. -p:: --patch:: Interactively select hunks in the difference between the - `` (or the index, if unspecified) and the working - tree. See the ``Interactive Mode'' section of linkgit:git-add[1] - to learn how to operate the `--patch` mode. + restore source and the restore location. See the ``Interactive + Mode'' section of linkgit:git-add[1] to learn how to operate + the `--patch` mode. ++ +Note that `--patch` can accept no pathspec and will prompt to restore +all modified paths. -W:: --worktree:: --I:: ---index:: +-S:: +--staged:: Specify the restore location. If neither option is specified, - by default the working tree is restored. If `--index` is - specified without `--worktree` or `--source`, `--source=HEAD` - is implied. These options only make sense to use with - `--source`. + by default the working tree is restored. Specifying `--staged` + will only restore the index. Specifying both restores both. -q:: --quiet:: - Quiet, suppress feedback messages. + Quiet, suppress feedback messages. Implies `--no-progress`. --progress:: --no-progress:: @@ -58,16 +70,10 @@ OPTIONS is specified. This flag enables progress reporting even if not attached to a terminal, regardless of `--quiet`. --f:: ---force:: - If `--source` is not specified, unmerged entries are left alone - and will not fail the operation. Unmerged entries are always - replaced if `--source` is specified, regardless of `--force`. - --ours:: --theirs:: - Check out stage #2 ('ours') or #3 ('theirs') for unmerged - paths. + When restoring files in the working tree from the index, use + stage #2 ('ours') or #3 ('theirs') for unmerged paths. + Note that during `git rebase` and `git pull --rebase`, 'ours' and 'theirs' may appear swapped. See the explanation of the same options @@ -75,67 +81,64 @@ in linkgit:git-checkout[1] for details. -m:: --merge:: - Recreate the conflicted merge in the specified paths. + When restoring files on the working tree from the index, + recreate the conflicted merge in the unmerged paths. --conflict=