Git Back in Time the Right Way

git revert vs. git reset

Help! I want to delete my unpublished commits!

git reset --hard <hash-or-ref>//example: git reset --hard 65806eb

Help! I want to delete my published commits!

git revert <hash-or-ref>
//example: git revert 65806eb
//Accept incoming changes from parent if asked
git revert HEAD
//This reverts to the most recent commit published without using a commit hash or reference

Help! I pushed and accidentally did git reset instead of git revert and now I can’t push to remote branch!

>>Your branch is behind 'origin/main' by n commits, and can be fast-forwarded.
git push --force origin <branch-name>
//example: git push --force origin main

Help! I’ve staged changes that I haven’t committed but a team member needs me to fix an urgent bug!

git stash 
//save staged changes
git stash apply
//apply stashed changes
git stash clear
//delete stashed changes

//Developer @ FightPandemics

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store