Skip to content

Instantly share code, notes, and snippets.

@alexislucena
Created November 14, 2016 08:56
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save alexislucena/ebf84a2d16d27ffd23c2fbbdbe1361e1 to your computer and use it in GitHub Desktop.
Save alexislucena/ebf84a2d16d27ffd23c2fbbdbe1361e1 to your computer and use it in GitHub Desktop.
Git: How to uncommit my last commit in git

To keep the changes from the commit you want to undo

$ git reset --soft HEAD^

To destroy the changes from the commit you want to undo

$ git reset --hard HEAD^

You can also say

$ git reset --soft HEAD~2

to go back 2 commits.

If you are on Windows you will need to put HEAD or commit hash in quotes.

$ git reset --soft "HEAD^"
$ git reset --soft "asdf"

Source:
http://stackoverflow.com/a/13480388/2050561

@LizSafina
Copy link

Thank you!

@satbeeer
Copy link

satbeeer commented Feb 2, 2021

Thanks alexislucena, its really helpful.

@shahab-ab
Copy link

when i run the above command I get the following errro
fatal: ambiguous argument '–-soft': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git [...] -- [...]'

@alexislucena
Copy link
Author

alexislucena commented Sep 7, 2021

when i run the above command I get the following errro
fatal: ambiguous argument '–-soft': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git [...] -- [...]'

@shahab-ab from your error message, it seems you are using a dash character that is not the standard, – instead of -

@shahab-ab
Copy link

@alexislucena thank you.. it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment