This question already has an answer here:<ul><li> <a href="/questions/8563558/post-mortem-unit-testing" dir="ltr" rel="nofollow">Post-mortem unit testing</a> <span class="question-originals-answer-count"> 4 answers </span> </li> </ul>
I want to go back to prior commits and run my program until I found out where something broke without deleting or affecting my commits. Once I find the last commit where it was working I can see what changed the go back to the current commit and fix it.
How would I do this?Answer1:
You should try using
git bisect. This functionality allows you to essentially binary search through your commits. You pick a commit when things were still good, and a commit when things are broken, and proceed from there.
Check out this page for a tutorial:
<a href="http://www-cs-students.stanford.edu/~blynn/gitmagic/ch05.html" rel="nofollow">http://www-cs-students.stanford.edu/~blynn/gitmagic/ch05.html</a>
(Search for "Where Did It All Go Wrong?")Answer2:
Git provides just the right command for that:
git bisect. It will perform a binary search and allows you to mark each tested commit either
Start the bisect procedure with:
git bisect start HEAD <last good commit>
Then build your source, run it, check for errors, and finally mark it:
git bisect good # or: git bisect bad
If you cannot test a commit (build broken, etc.), skip it with
git bisect skip.
Do that until you found the first <em>bad</em> commit. To get back to your original commit, run
git bisect reset.
If you just want to go back some commits to test you can do:
git checkout SHA