Recommit of @d153e9c Changes to PR #114.

Added -s --soft arguments as well.
Default roll-back one with HEAD^ and only using ~ if commit count more than 1.
Added auto complete.
Updated documentation.
Attitude adjustment: don't throw errors and say NO as suggested in #114, have a can do attitude instead, leave the errors up to git to report.
This commit is contained in:
nickl- 2012-07-22 22:57:19 +02:00
parent 1f2b3ea203
commit 501d4b2759
4 changed files with 41 additions and 35 deletions

View file

@ -1,27 +1,19 @@
#!/bin/sh
hard='no'
digit=1
back="^"
parseArgs () {
for var in "$@"; do
if [ "$var" = "--hard" -o "$var" = "-h" ]; then
hard='yes';
elif `echo $var | grep -q [^[:digit:]]`; then
echo "You entered an invalid option. Valid options are [--hard|-h] [commitcount]." 1>&2
exit 1;
else
digit=$var
fi
done
}
parseArgs $@
if [ "$hard" = "yes" ]; then
git reset --hard HEAD~$digit
else
git reset --soft HEAD~$digit
git reset
fi
case "$1" in
-h|--hard)
test $2 -gt 1 > /dev/null 2>&1 && back="~$2"
git reset --hard HEAD$back && exit 0;
;;
-s|--soft)
test $2 -gt 1 > /dev/null 2>&1 && back="~$2"
;;
*)
test $1 -gt 1 > /dev/null 2>&1 && back="~$1"
;;
esac
git reset --soft HEAD$back
git reset

View file

@ -7,16 +7,16 @@
\fBgit\-undo\fR \- Remove latest commits
.
.SH "SYNOPSIS"
\fBgit\-undo\fR [<commitcount>] [\-\-hard|\-h]
\fBgit\-undo\fR [<commitcount>] [\-s, \-\-soft, \-h, \-\-hard]
.
.SH "DESCRIPTION"
Removes the latest commits\.
.
.SH "OPTIONS"
<commitcount>
\-\-soft or \-s
.
.P
Number of commits to remove\. Defaults to \fI1\fR, thus remove the latest commit\.
This is the default, only rolls back the commit but changes remain un\-staged\.
.
.P
\-\-hard or \-h
@ -24,6 +24,12 @@ Number of commits to remove\. Defaults to \fI1\fR, thus remove the latest commit
.P
This option wipes your commit(s), so that your changes cannot be recovered\. Use with care\.
.
.P
<commitcount>
.
.P
Number of commits to remove\. Defaults to \fI1\fR, thus remove the latest commit\.
.
.SH "EXAMPLES"
Removes the latest commit\.
.
@ -51,7 +57,7 @@ $ git undo 3
.IP "" 0
.
.SH "AUTHOR"
Written by Kenneth Reitz <\fIme@kennethreitz\.com\fR>
Written by Kenneth Reitz <\fIme@kennethreitz\.com\fR> and Nick Lombard <\fIgithub@jigsoft\.co\.za\fR>
.
.SH "REPORTING BUGS"
<\fIhttp://github\.com/visionmedia/git\-extras/issues\fR>

View file

@ -76,7 +76,7 @@
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<p><code>git-undo</code> [&lt;commitcount&gt;] [--hard|-h]</p>
<p><code>git-undo</code> [&lt;commitcount&gt;] [-s, --soft, -h, --hard]</p>
<h2 id="DESCRIPTION">DESCRIPTION</h2>
@ -84,14 +84,18 @@
<h2 id="OPTIONS">OPTIONS</h2>
<p> &lt;commitcount&gt;</p>
<p> --soft or -s</p>
<p> Number of commits to remove. Defaults to <em>1</em>, thus remove the latest commit.</p>
<p> This is the default, only rolls back the commit but changes remain un-staged.</p>
<p> --hard or -h</p>
<p> This option wipes your commit(s), so that your changes cannot be recovered. Use with care.</p>
<p> &lt;commitcount&gt;</p>
<p> Number of commits to remove. Defaults to <em>1</em>, thus remove the latest commit.</p>
<h2 id="EXAMPLES">EXAMPLES</h2>
<p> Removes the latest commit.</p>
@ -106,7 +110,7 @@
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Kenneth Reitz &lt;<a href="&#109;&#97;&#105;&#108;&#x74;&#111;&#58;&#109;&#x65;&#x40;&#x6b;&#x65;&#x6e;&#110;&#x65;&#116;&#104;&#114;&#101;&#x69;&#116;&#x7a;&#46;&#99;&#111;&#x6d;" data-bare-link="true">&#x6d;&#101;&#64;&#107;&#101;&#110;&#110;&#101;&#116;&#x68;&#x72;&#101;&#105;&#116;&#x7a;&#x2e;&#x63;&#x6f;&#x6d;</a>&gt;</p>
<p>Written by Kenneth Reitz &lt;<a href="&#109;&#x61;&#105;&#108;&#116;&#111;&#x3a;&#x6d;&#x65;&#x40;&#x6b;&#101;&#x6e;&#110;&#101;&#116;&#104;&#114;&#101;&#x69;&#x74;&#122;&#46;&#99;&#x6f;&#109;" data-bare-link="true">&#109;&#101;&#64;&#x6b;&#x65;&#110;&#110;&#x65;&#116;&#104;&#114;&#101;&#x69;&#x74;&#x7a;&#46;&#x63;&#111;&#109;</a>&gt; and Nick Lombard &lt;<a href="&#x6d;&#97;&#x69;&#x6c;&#116;&#111;&#58;&#103;&#105;&#116;&#x68;&#x75;&#x62;&#x40;&#x6a;&#105;&#x67;&#115;&#111;&#102;&#116;&#46;&#99;&#111;&#46;&#122;&#x61;" data-bare-link="true">&#103;&#x69;&#x74;&#x68;&#x75;&#x62;&#64;&#106;&#x69;&#103;&#x73;&#x6f;&#x66;&#x74;&#x2e;&#99;&#111;&#46;&#x7a;&#97;</a>&gt;</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>

View file

@ -3,7 +3,7 @@ git-undo(1) -- Remove latest commits
## SYNOPSIS
`git-undo` [&lt;commitcount&gt;] [--hard|-h]
`git-undo` [&lt;commitcount&gt;] [-s, --soft, -h, --hard]
## DESCRIPTION
@ -11,14 +11,18 @@ git-undo(1) -- Remove latest commits
## OPTIONS
&lt;commitcount&gt;
--soft or -s
Number of commits to remove. Defaults to *1*, thus remove the latest commit.
This is the default, only rolls back the commit but changes remain un-staged.
--hard or -h
This option wipes your commit(s), so that your changes cannot be recovered. Use with care.
&lt;commitcount&gt;
Number of commits to remove. Defaults to *1*, thus remove the latest commit.
## EXAMPLES
Removes the latest commit.
@ -31,7 +35,7 @@ git-undo(1) -- Remove latest commits
## AUTHOR
Written by Kenneth Reitz &lt;<me@kennethreitz.com>&gt;
Written by Kenneth Reitz &lt;<me@kennethreitz.com>&gt; and Nick Lombard &lt;<github@jigsoft.co.za>&gt;
## REPORTING BUGS