Search code examples
gitgit-bisect

bisect everything, from initial commit


Say I have a small project with a very fast test script, and I just want to bisect everything, from the initial commit to the curret commit. How can I do that?

To clarify, I don't want to waste time identifying a commit that is good and a commit that is bad, so I'm looking for a quick way to mark the latest commit as bad, and the initial commit as good.


Solution

  • git bisect start
    git bisect good
    git bisect bad `git rev-list --max-parents=0 HEAD`
    git bisect run ./test.sh
    

    Or incorporate these commands into an alias, e.g.:

    bisect-all = !git bisect start && git bisect bad &&\
            git bisect good `git rev-list --max-parents=0 --first-parent HEAD`
    

    And then just use git bisect-all, git bisect run ./test.sh.

    Creating an alias to handle the whole process is slightly more complicated:

    quick-bisect = !sh -c 'git bisect start && git bisect bad &&\
            git bisect good `git rev-list --max-parents=0 --first-parent HEAD` &&\
            git bisect run "$@" && git bisect reset' -
    

    But with that, you can simply run git quick-bisect ./test.sh.


    If you're using a version of git older than 1.7.4.2, you won't have the --max-parents option, so will need to use something like git rev-list HEAD | tail -n 1 instead.