git reset (soft, mixed, hard)
`git reset` moves the current branch pointer to a different commit, and can also change the staging area and working directory depending on the mode used. It's a powerful tool for undoing commits.
The three modes are: `--soft` (keeps changes staged), `--mixed` (default, unstages changes but keeps them in the working directory), and `--hard` (discards changes completely).
git reset --soft <commit>
git reset --mixed <commit>
git reset --hard <commit>Soft and mixed reset
`git reset --soft HEAD~1` undoes the last commit but keeps changes staged. `git reset --mixed HEAD~1` (the default) undoes the commit and unstages changes, but keeps them in your files.
Hard reset (dangerous)
`git reset --hard HEAD~1` undoes the commit and permanently discards all related changes from the working directory. Use with extreme caution.
git reset --soft HEAD~1Undoes the last commit but keeps its changes staged, ready to be re-committed.
git reset --hard HEAD~1HEAD is now at a3f5c9e Add login validationUndoes the last commit and discards all its changes completely from the working directory.
Key points
- git reset moves the branch pointer to a different commit.
- --soft keeps changes staged after the reset.
- --mixed (default) unstages but keeps changes in your files.
- --hard permanently discards changes โ use with caution.
