How can I go back and test where something broke? [duplicate]


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?


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?")


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 good or bad

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


  • Optimize Binary Search
  • Given 3 Points, How to Construct An Arc that Passes Through Them?
  • How to do a binary search for a range of the same value?
  • Official Django Tutorial Part1: RuntimeError: maximum recursion depth exceeded in cmp
  • Read stdin in chunks in Bash pipe
  • Does SmartGit support git-svn?
  • Quick Question About Get and Set
  • Find VMID for running instance
  • Backward compatibility of Python 3.5 for external modules
  • How to handle elastic beanstalk deployment so it uploads only changed files
  • Hibernate to update table schema
  • How to install node-mysql?
  • Clarification on min distance on LocationManager.requestLocationUpdates method, min Distance paramet
  • as3-flash: any way to access all the instances placed in different frames from document class?
  • How to use carriage return with multiple line?
  • Abort upload large uploads after reading headers
  • Cancel a live stream “fast motion” catch-up in Flash
  • Google Custom Search with transparent background
  • Spring Data JPA custom method causing PropertyReferenceException
  • Insert into database using onclick function
  • QLineEdit password safety
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • What is Eclipse's Declaration View used for?
  • Bug in WPF DataGrid
  • Excel - Autoshape get it's name from cell (value)
  • TFS: Get latest causes slow project reloading
  • Javascript Callbacks with Object constructor
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • Can I make an Android app that runs a web view in Chrome 39?
  • htaccess rewriting URLs with multiple forward slashes
  • Display Images one by one with next and previous functionality
  • How to make Safari send if-modified-since header?
  • How do you troubleshoot character encoding problems?
  • Web-crawler for facebook in python
  • Google cloud sdk not working when python points python3
  • PHP: When would you need the self:: keyword?
  • A cron job substitute?
  • Acquiring multiple attributes from .xml file in c#
  • reshape alternating columns in less time and using less memory
  • How can I use threading to 'tick' a timer to be accessed by other threads?