You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reset rewinds history (files + commits) back to the previous commits
Revert rewinds your files back to the previous commits by adding a new commit to show this
You should use revert (especially if you have pushed) as it does not rewrite history
Git Reset
# If you are pulling, rebasing or your new code is a mess, and you want to return to the last committed point:# Note that this does not delete newly created files# git clean -f -d will remove newly created files and directories (BEWARE!)
git reset --hard
# reset to the last commit# HEAD is the current commit, HEAD^ is the last commit# HEAD~2 is the 3rd, HEAD~3 is the 4th and so on...
git reset --hard HEAD^
# reset to a particular commit
git reset --hard be47384a
Git Revert
# Revert the commit 0766c053# Note that commit may not necessary be the last commit, it can be ANY commit
git revert 0766c053
# Revert the changes specified by the fourth last commit in HEAD and create a new commit with the reverted changes.
git revert HEAD~3
# Revert the changes done by commits from the fifth last commit in master (included) to the third last commit in master (included), but do not create any commit with the reverted changes. The revert only modifies the working tree and the index.
git revert -n master~5..master~2