To go back to the last known working commit:
$ git checkout HEAD~40
Will checkout a detached HEAD state to 40 commits before the HEAD (or you can just use the commit hash).
To find the bad commit you can use git bisect
, like so:
$ git bisect start
$ git bisect HEAD
$ git bisect HEAD~40
This process will do a binary search on the bad commit-good commit range to help you find where the bug is. See the docs for more details on how to run this process. But generally speaking, it's best to have a script that can run your tests (and exists with exit code 0
upon success), which can automate the entire process:
$ git bisect run run_tests.sh args