Skip to content

Commit 044b06b

Browse files
authored
Merge pull request #723 from bittner/feature/git-undo-soft-leave-changes-staged
Make `git undo -s` restore the staging area
2 parents 5b0a9d2 + b7d5075 commit 044b06b

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ Patches and Suggestions
168168
- Nick Campbell
169169
- Nick Payne
170170
- Niklas Fiekas
171+
- Peter Bittner
171172
- Prayag Verma
172173
- R. Martinho Fernandes
173174
- Raphael Fleischlin

bin/git-undo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ EOL
2323
;;
2424
--hard)
2525
test $2 -gt 1 > /dev/null 2>&1 && back="~$2"
26-
git reset --hard HEAD$back && exit 0;
26+
git reset --hard HEAD$back
2727
;;
2828
-s|--soft)
2929
test $2 -gt 1 > /dev/null 2>&1 && back="~$2"
30+
git reset --soft HEAD$back
3031
;;
3132
*)
3233
test $1 -gt 1 > /dev/null 2>&1 && back="~$1"
34+
git reset --soft HEAD$back
35+
git reset
3336
;;
3437
esac
35-
36-
git reset --soft HEAD$back
37-
git reset

man/git-undo.1

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "GIT\-UNDO" "1" "April 2018" "" "Git Extras"
4+
.TH "GIT\-UNDO" "1" "June 2018" "" "Git Extras"
55
.
66
.SH "NAME"
77
\fBgit\-undo\fR \- Remove latest commits
@@ -16,7 +16,7 @@ Removes the latest commits\.
1616
\-\-soft or \-s
1717
.
1818
.P
19-
This is the default, only rolls back the commit but changes remain un\-staged\.
19+
Rolls back the commit(s) but leaves the changes in the staging area\.
2020
.
2121
.P
2222
\-\-hard or \-h
@@ -44,6 +44,19 @@ $ git undo
4444
.IP "" 0
4545
.
4646
.P
47+
Removes the latest commit, restoring the staging area\.
48+
.
49+
.IP "" 4
50+
.
51+
.nf
52+
53+
$ git undo \-s
54+
.
55+
.fi
56+
.
57+
.IP "" 0
58+
.
59+
.P
4760
Remove the latest 3 commits:
4861
.
4962
.IP "" 4

man/git-undo.html

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git-undo.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ git-undo(1) -- Remove latest commits
1313

1414
--soft or -s
1515

16-
This is the default, only rolls back the commit but changes remain un-staged.
16+
Rolls back the commit(s) but leaves the changes in the staging area.
1717

1818
--hard or -h
1919

@@ -30,6 +30,10 @@ git-undo(1) -- Remove latest commits
3030

3131
$ git undo
3232

33+
Removes the latest commit, restoring the staging area.
34+
35+
$ git undo -s
36+
3337
Remove the latest 3 commits:
3438

3539
$ git undo 3

0 commit comments

Comments
 (0)