This is a git command I use quite often, so I searched a little about the different options and their effects:
Command | Commit History | Staging Area | Working Directory |
---|---|---|---|
git reset HEAD~ | Removes last commit | Unstages changes | Keeps changes |
git reset --soft HEAD~ | Removes last commit | Keeps changes staged | Keeps changes |
git reset --hard HEAD~ | Removes last commit | Discards all changes | Discards all changes |
HEAD~
refers to the commit just before the currentHEAD
(i.e., the previous commit).
What happens when you run git reset HEAD~
:
- The branch pointer (
HEAD
) is moved back by one commit, undoing the latest commit from your branch history. - The changes from that commit are unstaged, but you can still see them in your working directory