2 Ways to save your life when you confused push any code or file to your branch.



This content originally appeared on DEV Community and was authored by Pheak Pheasa

Way 1

1. Find your committed hash by :

git log

2. After found your commit hash you need revert it by :

git revert <commit-hash>

3. choose one at bellow with responsibility:

🟢 Uncommit last commit (keep files):

git reset --soft HEAD~1

✅ Files stay staged, just remove commit.

🟡 Uncommit & Unstage (keep changes in working directory):

git reset --mixed HEAD~1

✅ Files stay, but unstaged (not in commit).

🔴 Uncommit & Remove changes:

git reset --hard HEAD~1

⚠ Files & commit both gone! Careful!

🟣 Uncommit pushed commit (force push):

git reset --soft HEAD~1
git push --force

✅ Removes commit on remote branch too.

Way 2 in next post.


This content originally appeared on DEV Community and was authored by Pheak Pheasa