Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save viccon/c645d5ef603be72d126d32e98e2dc9d0 to your computer and use it in GitHub Desktop.

Select an option

Save viccon/c645d5ef603be72d126d32e98e2dc9d0 to your computer and use it in GitHub Desktop.
Protip: Bisecting a single commit

Situation: Some commit (on master, but not necessarily head of master) has broken things, but it's a big commit and it's not clear what part broke things.

% git checkout master
% git checkout -b bisect-branch
% git revert <offending commit>

(test here to make sure reverting fixed your problem)

% git bisect start
% git bisect good
% while [ "`git diff master`" != "" ]; do echo -e "y\nq\n" | git checkout -p master; git commit -m 'partial undo'; done

(test here to make sure we've recreated your problem)

% git bisect bad

Now just follow the bisect.

The while line has broken your commit up into small chunks, one commit per chunk. If a chunk has actually broken syntax (so you can't test either way), you can git bisect skip.

You can also s/master/any-reference-branch-or-tag-or-sha/g. And you can use s\ny\nq\n if you want even smaller chunks (but more risk of syntax errors).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment