mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
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:
parent
1f2b3ea203
commit
501d4b2759
38
bin/git-undo
38
bin/git-undo
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@
|
|||
|
||||
<h2 id="SYNOPSIS">SYNOPSIS</h2>
|
||||
|
||||
<p><code>git-undo</code> [<commitcount>] [--hard|-h]</p>
|
||||
<p><code>git-undo</code> [<commitcount>] [-s, --soft, -h, --hard]</p>
|
||||
|
||||
<h2 id="DESCRIPTION">DESCRIPTION</h2>
|
||||
|
||||
|
|
@ -84,14 +84,18 @@
|
|||
|
||||
<h2 id="OPTIONS">OPTIONS</h2>
|
||||
|
||||
<p> <commitcount></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> <commitcount></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 <<a href="mailto:me@kennethreitz.com" data-bare-link="true">me@kennethreitz.com</a>></p>
|
||||
<p>Written by Kenneth Reitz <<a href="mailto:me@kennethreitz.com" data-bare-link="true">me@kennethreitz.com</a>> and Nick Lombard <<a href="mailto:github@jigsoft.co.za" data-bare-link="true">github@jigsoft.co.za</a>></p>
|
||||
|
||||
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ git-undo(1) -- Remove latest commits
|
|||
|
||||
## SYNOPSIS
|
||||
|
||||
`git-undo` [<commitcount>] [--hard|-h]
|
||||
`git-undo` [<commitcount>] [-s, --soft, -h, --hard]
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
|
|
@ -11,14 +11,18 @@ git-undo(1) -- Remove latest commits
|
|||
|
||||
## OPTIONS
|
||||
|
||||
<commitcount>
|
||||
--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.
|
||||
|
||||
<commitcount>
|
||||
|
||||
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 <<me@kennethreitz.com>>
|
||||
Written by Kenneth Reitz <<me@kennethreitz.com>> and Nick Lombard <<github@jigsoft.co.za>>
|
||||
|
||||
## REPORTING BUGS
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue