Revert Git to last commit

 

If you want to revert everything back to the last commit and discard all local changes, use this ๐Ÿ‘‡

๐Ÿ”ฅ Hard reset (most common & safest)

This restores your working tree and index to the latest commit.

git reset --hard HEAD

What this does

  • ❌ Discards all modified files

  • ❌ Discards all staged files

  • ❌ Discards all untracked changes in tracked files

  • ✅ Leaves your repo exactly as the last commit


๐Ÿงน Also remove untracked files (optional but often needed)

If you also want to delete untracked files and folders:

git clean -fd

Or preview first (recommended):

git clean -fdn

✅ One-liner (full nuclear option)

git reset --hard HEAD && git clean -fd

⚠️ Important warning

This is irreversible unless:

  • Changes were committed

  • Or stashed

  • Or still exist elsewhere


Total page views:

Comments

Popular posts from this blog

Useful aliases

Start all Docker containers