[RFC PATCH v2 1/3] Introduce git-unstage
From: Thomas Rast <hidden>
Date: 2016-06-15 22:47:05
Subsystem:
documentation, kernel build + files below scripts/ (unless maintained elsewhere), the rest · Maintainers:
Jonathan Corbet, Nathan Chancellor, Nicolas Schier, Linus Torvalds
The new command 'git unstage' is the precise opposite of 'git stage' (i.e., git-add). As such, it is the same as 'git reset --' unless the current branch is unborn. Signed-off-by: Thomas Rast <redacted> --- So I decided I had wished for these frequently enough to actually implement them. I ran out of time before getting to the tests, but the rest should be there. v1 had a bug where it would not correctly detect the changed files, this is fixed in the new patch (now 3/3). Documentation/git-unstage.txt | 26 ++++++++++++++++++++++++++ Makefile | 1 + git-unstage.sh | 26 ++++++++++++++++++++++++++ wt-status.c | 6 +----- 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 Documentation/git-unstage.txt create mode 100644 git-unstage.sh
diff --git a/Documentation/git-unstage.txt b/Documentation/git-unstage.txt
new file mode 100644
index 0000000..49d09fb
--- /dev/null
+++ b/Documentation/git-unstage.txt@@ -0,0 +1,26 @@ +git-unstage(1) +============== + +NAME +---- +git-unstage - Remove changes to a file from the staging area + + +SYNOPSIS +-------- +[verse] +'git unstage' <paths> ... + + +DESCRIPTION +----------- + +Overwrites the staged changes to the 'paths' with the values from +HEAD, so that they are not included in the next commit. The worktree +is not affected. (This is the same as `git reset \-- <paths>` unless +you are on an unborn branch.) + + +SEE ALSO +-------- +linkgit:git-reset[1]
diff --git a/Makefile b/Makefile
index 75b9dcb..9e48fdc 100644
--- a/Makefile
+++ b/Makefile@@ -329,6 +329,7 @@ SCRIPT_SH += git-request-pull.sh SCRIPT_SH += git-sh-setup.sh SCRIPT_SH += git-stash.sh SCRIPT_SH += git-submodule.sh +SCRIPT_SH += git-unstage.sh SCRIPT_SH += git-web--browse.sh SCRIPT_PERL += git-add--interactive.perl
diff --git a/git-unstage.sh b/git-unstage.sh
new file mode 100644
index 0000000..7f99adf
--- /dev/null
+++ b/git-unstage.sh@@ -0,0 +1,26 @@ +#!/bin/sh + +SUBDIRECTORY_OK=Yes +OPTIONS_KEEPDASHDASH= +OPTIONS_SPEC="\ +git unstage file ... +--" + +. git-sh-setup + + +case "$1" in + --) + if [ $# -eq 1 ]; then + die "You must specify at least one file to unstage" + fi + if git rev-parse -q --verify HEAD >/dev/null; then + exec git reset "$@" + else + exec git rm --cached "$@" + fi + ;; + *) + usage + ;; +esac
diff --git a/wt-status.c b/wt-status.c
index 47735d8..f1a74a4 100644
--- a/wt-status.c
+++ b/wt-status.c@@ -62,11 +62,7 @@ static void wt_status_print_cached_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER); color_fprintf_ln(s->fp, c, "# Changes to be committed:"); - if (!s->is_initial) { - color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference); - } else { - color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)"); - } + color_fprintf_ln(s->fp, c, "# (use \"git unstage %s <file>...\" to unstage)", s->reference); color_fprintf_ln(s->fp, c, "#"); }
--
1.6.4.rc2.217.g74c0b.dirty