From b7d507567bf65458afc2ca1418986f220dac9ac9 Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Thu, 21 Jun 2018 13:16:24 +0200 Subject: [PATCH] Make `git undo -s` restore the staging area --- AUTHORS | 1 + bin/git-undo | 8 ++++---- man/git-undo.1 | 17 +++++++++++++++-- man/git-undo.html | 11 ++++++++--- man/git-undo.md | 6 +++++- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index aa22e96..3767593 100644 --- a/AUTHORS +++ b/AUTHORS @@ -168,6 +168,7 @@ Patches and Suggestions - Nick Campbell - Nick Payne - Niklas Fiekas +- Peter Bittner - Prayag Verma - R. Martinho Fernandes - Raphael Fleischlin diff --git a/bin/git-undo b/bin/git-undo index d0d5d2d..e6742d2 100755 --- a/bin/git-undo +++ b/bin/git-undo @@ -23,15 +23,15 @@ EOL ;; --hard) test $2 -gt 1 > /dev/null 2>&1 && back="~$2" - git reset --hard HEAD$back && exit 0; + git reset --hard HEAD$back ;; -s|--soft) test $2 -gt 1 > /dev/null 2>&1 && back="~$2" + git reset --soft HEAD$back ;; *) test $1 -gt 1 > /dev/null 2>&1 && back="~$1" + git reset --soft HEAD$back + git reset ;; esac - -git reset --soft HEAD$back -git reset diff --git a/man/git-undo.1 b/man/git-undo.1 index ee2325b..d982af1 100644 --- a/man/git-undo.1 +++ b/man/git-undo.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "GIT\-UNDO" "1" "April 2018" "" "Git Extras" +.TH "GIT\-UNDO" "1" "June 2018" "" "Git Extras" . .SH "NAME" \fBgit\-undo\fR \- Remove latest commits @@ -16,7 +16,7 @@ Removes the latest commits\. \-\-soft or \-s . .P -This is the default, only rolls back the commit but changes remain un\-staged\. +Rolls back the commit(s) but leaves the changes in the staging area\. . .P \-\-hard or \-h @@ -44,6 +44,19 @@ $ git undo .IP "" 0 . .P +Removes the latest commit, restoring the staging area\. +. +.IP "" 4 +. +.nf + +$ git undo \-s +. +.fi +. +.IP "" 0 +. +.P Remove the latest 3 commits: . .IP "" 4 diff --git a/man/git-undo.html b/man/git-undo.html index 80bc261..8ddb4ca 100644 --- a/man/git-undo.html +++ b/man/git-undo.html @@ -86,7 +86,7 @@

--soft or -s

-

This is the default, only rolls back the commit but changes remain un-staged.

+

Rolls back the commit(s) but leaves the changes in the staging area.

--hard or -h

@@ -104,6 +104,11 @@
$ git undo
 
+

Removes the latest commit, restoring the staging area.

+ +
$ git undo -s
+
+

Remove the latest 3 commits:

$ git undo 3
@@ -111,7 +116,7 @@
 
 

AUTHOR

-

Written by Kenneth Reitz <me@kennethreitz.com> and Nick Lombard <github@jigsoft.co.za>

+

Written by Kenneth Reitz <me@kennethreitz.com> and Nick Lombard <github@jigsoft.co.za>

REPORTING BUGS

@@ -124,7 +129,7 @@
  1. -
  2. April 2018
  3. +
  4. June 2018
  5. git-undo(1)
diff --git a/man/git-undo.md b/man/git-undo.md index f101f39..76bfeb1 100644 --- a/man/git-undo.md +++ b/man/git-undo.md @@ -13,7 +13,7 @@ git-undo(1) -- Remove latest commits --soft or -s - This is the default, only rolls back the commit but changes remain un-staged. + Rolls back the commit(s) but leaves the changes in the staging area. --hard or -h @@ -30,6 +30,10 @@ git-undo(1) -- Remove latest commits $ git undo + Removes the latest commit, restoring the staging area. + + $ git undo -s + Remove the latest 3 commits: $ git undo 3