Search code examples
gitrevert

I want to revert my master branch to state 8 commits ago


I just realized I introduced a memory leak somewhere in the last 8 commits. Easiest solution is to revert to 8 commits ago, then carefully add the changes back in. What is the easiest way of doing this?

Thanks!


Solution

  • Take a look at git bisect. It sounds like exactly what you are looking for.

    Basically, you tell it a known good point and a known bad point in your history, and then it helps you perform a binary search until you find the offending commit.

    Here's a tutorial on its use: http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#using-bisect

    But, if you don't want to do it that way, create a temporary branch where you are right now and either do a bunch of git reset HEAD^ to go up one commit at a time, or do git reset HEAD~8 and then git cherry-pick <sha1> for each subsequent commit between you and your temporary commit.