How to revert the last X commits?

The simplest way of revering commits is to reset your head to the last commit you want and just discard the changes, here is how you can do it.

git reflog
# you will see a list of every thing you've done in git, across all branches!
# each one has an index HEAD@{index}
# find the one before you broke everything

git reset HEAD@{index}
# magic time machine

You can use this to get back stuff you accidentally deleted or remove some things you tried that broke the repo.

Originally Posted On: OhShitGit

Subscribe to GIT.WTF!?!

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]