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
# Reset the index and working tree to the desired tree
# Ensure you have no uncommitted changes that you want to keep
git reset --hard 56e05fced
# Move the branch pointer back to the previous HEAD
git reset --soft HEAD@{1}
git commit -m "Reverting to the state of the project at f414f31"
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
$ 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.