git-undo: add confirmation when -h is specified

This commit is contained in:
spacewander 2018-02-07 10:37:55 +08:00
parent 8216e6bbbc
commit 16591d3788
4 changed files with 26 additions and 6 deletions

View file

@ -3,7 +3,25 @@
back="^"
case "$1" in
-h|--hard)
-h)
cat << EOL
This will erase any changes since your last commit.
If you want to get help info, run "git undo --help" instead.
Do you want to continue? [yN]"
EOL
read -r res
case "${res}" in
"Y" | "y")
test $2 -gt 1 > /dev/null 2>&1 && back="~$2"
git reset --hard HEAD$back
exit $?
;;
* )
exit 0
;;
esac
;;
--hard)
test $2 -gt 1 > /dev/null 2>&1 && back="~$2"
git reset --hard HEAD$back && exit 0;
;;

View file

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-UNDO" "1" "December 2015" "" ""
.TH "GIT\-UNDO" "1" "February 2018" "" ""
.
.SH "NAME"
\fBgit\-undo\fR \- Remove latest commits
@ -22,7 +22,7 @@ This is the default, only rolls back the commit but changes remain un\-staged\.
\-\-hard or \-h
.
.P
This option wipes your commit(s), so that your changes cannot be recovered\. Use with care\.
This option wipes your commit(s), so that your changes cannot be recovered\. Use with care\. To avoid being confused with \fB\-\-help\fR, there will be a confirmation when \fB\-h\fR is specified\.
.
.P
<commitcount>

View file

@ -90,7 +90,8 @@
<p> --hard or -h</p>
<p> This option wipes your commit(s), so that your changes cannot be recovered. Use with care.</p>
<p> This option wipes your commit(s), so that your changes cannot be recovered. Use with care.
To avoid being confused with <code>--help</code>, there will be a confirmation when <code>-h</code> is specified.</p>
<p> &lt;commitcount&gt;</p>
@ -110,7 +111,7 @@
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Kenneth Reitz &lt;<a href="&#x6d;&#x61;&#x69;&#x6c;&#x74;&#x6f;&#58;&#109;&#101;&#x40;&#107;&#101;&#x6e;&#x6e;&#x65;&#x74;&#x68;&#x72;&#x65;&#x69;&#x74;&#122;&#46;&#99;&#x6f;&#x6d;" data-bare-link="true">&#109;&#x65;&#64;&#x6b;&#101;&#x6e;&#110;&#101;&#x74;&#x68;&#x72;&#x65;&#x69;&#x74;&#122;&#x2e;&#x63;&#x6f;&#x6d;</a>&gt; and Nick Lombard &lt;<a href="&#109;&#x61;&#105;&#x6c;&#116;&#x6f;&#58;&#103;&#105;&#x74;&#x68;&#x75;&#x62;&#64;&#x6a;&#105;&#x67;&#x73;&#111;&#x66;&#116;&#46;&#99;&#x6f;&#x2e;&#x7a;&#x61;" data-bare-link="true">&#x67;&#105;&#116;&#104;&#x75;&#x62;&#64;&#106;&#x69;&#x67;&#x73;&#111;&#x66;&#116;&#x2e;&#99;&#x6f;&#46;&#122;&#97;</a>&gt;</p>
<p>Written by Kenneth Reitz &lt;<a href="&#109;&#97;&#105;&#x6c;&#x74;&#111;&#58;&#x6d;&#x65;&#x40;&#107;&#x65;&#x6e;&#110;&#x65;&#x74;&#x68;&#x72;&#101;&#105;&#116;&#x7a;&#46;&#x63;&#x6f;&#109;" data-bare-link="true">&#x6d;&#101;&#64;&#107;&#x65;&#x6e;&#110;&#x65;&#116;&#x68;&#114;&#101;&#x69;&#x74;&#x7a;&#x2e;&#99;&#111;&#x6d;</a>&gt; and Nick Lombard &lt;<a href="&#109;&#97;&#105;&#x6c;&#116;&#x6f;&#x3a;&#x67;&#x69;&#116;&#104;&#117;&#x62;&#64;&#106;&#105;&#x67;&#x73;&#111;&#102;&#x74;&#46;&#99;&#111;&#x2e;&#x7a;&#x61;" data-bare-link="true">&#103;&#105;&#116;&#x68;&#117;&#98;&#64;&#x6a;&#105;&#x67;&#x73;&#x6f;&#102;&#x74;&#x2e;&#99;&#x6f;&#x2e;&#x7a;&#x61;</a>&gt;</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
@ -123,7 +124,7 @@
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>December 2015</li>
<li class='tc'>February 2018</li>
<li class='tr'>git-undo(1)</li>
</ol>

View file

@ -18,6 +18,7 @@ git-undo(1) -- Remove latest commits
--hard or -h
This option wipes your commit(s), so that your changes cannot be recovered. Use with care.
To avoid being confused with `--help`, there will be a confirmation when `-h` is specified.
&lt;commitcount&gt;