From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 041C020248 for ; Thu, 11 Apr 2019 13:12:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726577AbfDKNMg (ORCPT ); Thu, 11 Apr 2019 09:12:36 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35775 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726106AbfDKNMg (ORCPT ); Thu, 11 Apr 2019 09:12:36 -0400 Received: by mail-pf1-f193.google.com with SMTP id t21so3457641pfh.2 for ; Thu, 11 Apr 2019 06:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xC6+vy/KjSZjQUGWAcsWM/BOX6d276GWCYSmV+UIxx4=; b=vAyEMm7P7Z3lXUbf5OwZHe3Wx8M3Yjxq7TJ+iKI6STzjCks25hZPcQ+Vhlo/KwZScR zj9nei4HJvwj/oM8bJwygic9VGakwzZwtxSL0UW+XA6MCZyfb2VMFBRyxFv19DsEVhhO oSO3aVpVRKr/WkNoCRPL2NP3VEGe3dcW6FoaNBdtlQ2cj16PJh7MmRv0Oj5u01sDXFhZ rJCOqSMLP9WU0AlDCA03nlIT2d69feFYK/mXAbhk6v+VXoFUicL/f2LXDWFcSFd2VHw1 q/CHypNvl5JSQRtN3BtwoQEZkMC4w4WSLTnvFwHVN/EVG6X4YPI2JEtFwFsiSkBAYjAN V0Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xC6+vy/KjSZjQUGWAcsWM/BOX6d276GWCYSmV+UIxx4=; b=KpXwPfE1WyEAY+Zu3NkDUaHC3ncr4cC1FcFCdfYMl+opc6RccOSMgezs/k09RhUQ8W JZ1PK5WGDr0IkyzvpDURVz0iIDrbzZwRe+CzQDqmJ2LMlnY3ZazyZDJUIMGMOXp7lMwd 9kGFMEod7WGnkFacCARQuSgn/Jh9Si3h22c9w9piU9nAgBC30LcmLohyAPZKscL7S9pm kmsoXuh01+nKEau/qMUb4xNRvChXslc3V7hciCVZqTRurTdsGLVvKnGrfxcSe0Hy+Zge X4l6GDnvCUg2KDA0+aQiuRWQ5K1HDgXUBkRdKEBtLv7LMuAUaTU1GxZ3/b9WxrphFQQe arGw== X-Gm-Message-State: APjAAAXVXl8zySFfVmDaFPRBshvKFA7fhBxR8HG/NI+OKl+WN8Gkggx3 0e6RUN8KFAKanlAblDrsEfo= X-Google-Smtp-Source: APXvYqyF3HdXHSDG0ZBVGdzqW/dD3hbjyLFelKViGNqoS4Y3IUYbdK4uKhit/dYIVegemewA0PmVuA== X-Received: by 2002:a63:4a5a:: with SMTP id j26mr46950930pgl.361.1554988354186; Thu, 11 Apr 2019 06:12:34 -0700 (PDT) Received: from ash ([116.102.217.71]) by smtp.gmail.com with ESMTPSA id h71sm7877032pge.49.2019.04.11.06.12.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 06:12:33 -0700 (PDT) Received: by ash (sSMTP sendmail emulation); Thu, 11 Apr 2019 20:12:27 +0700 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= To: pclouds@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, newren@gmail.com, Eric Sunshine , rybak.a.v@gmail.com, Johannes Schindelin , jacob.keller@gmail.com Subject: [PATCH v2 00/16] Add new command 'restore' Date: Thu, 11 Apr 2019 20:12:02 +0700 Message-Id: <20190411131218.19195-1-pclouds@gmail.com> X-Mailer: git-send-email 2.21.0.682.g30d2204636 In-Reply-To: <20190308101655.9767-1-pclouds@gmail.com> References: <20190308101655.9767-1-pclouds@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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=