diff --git a/bin/git-undo b/bin/git-undo index 5784377..aedc844 100755 --- a/bin/git-undo +++ b/bin/git-undo @@ -1,13 +1,27 @@ #!/bin/sh -if test $# -eq 0; then - git reset --soft HEAD~1 - git reset +hard='no' +digit=1 + +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 - if `echo $1 | grep -q [^[:digit:]]`; then - echo "$1 is not a number" 1>&2 - else - git reset --soft HEAD~$1 - git reset - fi + git reset --soft HEAD~$digit + git reset fi + diff --git a/man/git-undo.1 b/man/git-undo.1 index 3dbc81c..fb4e64a 100644 --- a/man/git-undo.1 +++ b/man/git-undo.1 @@ -1,13 +1,13 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "GIT\-UNDO" "1" "March 2011" "" "Git Extras" +.TH "GIT\-UNDO" "1" "June 2012" "" "" . .SH "NAME" \fBgit\-undo\fR \- Remove latest commits . .SH "SYNOPSIS" -\fBgit\-undo\fR [] +\fBgit\-undo\fR [] [\-\-hard|\-h] . .SH "DESCRIPTION" Removes the latest commits\. @@ -18,6 +18,12 @@ Removes the latest commits\. .P Number of commits to remove\. Defaults to \fI1\fR, thus remove the latest commit\. . +.P +\-\-hard or \-h +. +.P +This option wipes your commit(s), so that your changes cannot be recovered\. Use with care\. +. .SH "EXAMPLES" Removes the latest commit\. . diff --git a/man/git-undo.html b/man/git-undo.html index 5149dd7..6126a14 100644 --- a/man/git-undo.html +++ b/man/git-undo.html @@ -61,11 +61,11 @@ AUTHOR REPORTING BUGS SEE ALSO - +
  1. git-undo(1)
  2. -
  3. Git Extras
  4. +
  5. git-undo(1)
@@ -76,7 +76,7 @@

SYNOPSIS

-

git-undo [<commitcount>]

+

git-undo [<commitcount>] [--hard|-h]

DESCRIPTION

@@ -88,6 +88,10 @@

Number of commits to remove. Defaults to 1, thus remove the latest commit.

+

--hard or -h

+ +

This option wipes your commit(s), so that your changes cannot be recovered. Use with care.

+

EXAMPLES

Removes the latest commit.

@@ -102,20 +106,20 @@

AUTHOR

-

Written by Kenneth Reitz <me@kennethreitz.com>

+

Written by Kenneth Reitz <me@kennethreitz.com>

REPORTING BUGS

-

<http://github.com/visionmedia/git-extras/issues>

+

<http://github.com/visionmedia/git-extras/issues>

SEE ALSO

-

<http://github.com/visionmedia/git-extras>

+

<http://github.com/visionmedia/git-extras>

  1. -
  2. March 2011
  3. +
  4. June 2012
  5. git-undo(1)
diff --git a/man/git-undo.md b/man/git-undo.md index 55f344c..82694a4 100644 --- a/man/git-undo.md +++ b/man/git-undo.md @@ -3,7 +3,7 @@ git-undo(1) -- Remove latest commits ## SYNOPSIS -`git-undo` [<commitcount>] +`git-undo` [<commitcount>] [--hard|-h] ## DESCRIPTION @@ -15,6 +15,10 @@ git-undo(1) -- Remove latest commits Number of commits to remove. Defaults to *1*, thus remove the latest commit. + --hard or -h + + This option wipes your commit(s), so that your changes cannot be recovered. Use with care. + ## EXAMPLES Removes the latest commit.