xxxxxxxxxx
git reset --soft HEAD~1 # Undo commit
git reset <file-name> # Undo add
git reset # Undo add all files
git checkout -- . # discard changes in working directory
# FOR UNTRACKED FILES,
# discard changes in working directory needs another commands:
git clean -n # Print untracked files in working directory
git clean -i # Print untracked files and useful commands
git clean -f # Discard untracked files
git clean -d # Discard untracked directories in addition to untracked files
xxxxxxxxxx
# Uncommit the changes
git reset --soft HEAD~1
# Completely delete the changes
git reset --hard HEAD~1
xxxxxxxxxx
# KEEP CHANGES
git reset --soft HEAD~1
# REMOVE CHANGES
git reset --hard HEAD~1
xxxxxxxxxx
$ git revert [here comes the commit id]
-Note that this operation creates a new commit that reverts
all of the changes instead of removing given commit from history.
xxxxxxxxxx
If your commits are only LOCAL,
you can git reset --hard origin/<branch_name>
to move back to where the origin is.