Skip to content

Git Reset

Back to Git


⏮️ Git Reset

Git Reset updates your current head to the specified state. It is used to undo changes or move back in history.

Undo Last Commit (Soft)

Undo the last commit but keep changes in your working directory (staged):

git reset --soft HEAD~1

Undo Last Commit (Mixed)

Undo the last commit and unstage changes (commands default to mixed):

git reset HEAD~1

Hard Reset (Destructive)

Undo the last commit and delete all changes from the file system:

git reset --hard HEAD~1
Warning: You will lose any uncommitted work.

Reset to 2 Commits Back

git reset HEAD~2

🕵️ Git Reflog

Reflog (Reference Log) tracks updates to the tip of git branches. It allows you to recover "lost" commits after a reset.

View Reflog

To see all recent actions (last 90 days by default):

git reflog

Recover Lost Commit

If you accidentally did a hard reset, find the SHA in reflog and reset to it:

git reset --hard <commit-id>
Or using index:
git reset --hard HEAD@{2}


🧠 Quick Quiz — Reset

#

Which reset mode erases your file changes completely?


📝 Want More Practice?

👉 Start Git Beginner Quiz (20 Questions)


📬 DevopsPilot Weekly — Learn DevOps, Cloud & Gen AI the simple way.
👉 Subscribe here