If you want to undo your last instruction in one go, without having to use a text editor, you can use the following command:
git bisect log | head -n -2 > /tmp/fixed_bisect.log ; git bisect replay /tmp/fixed_bisect.log
It will remove the two last lines of the log (because there's a comment + the actual command it corresponds to), then save that to file and directly reuse it with bisect replay
. (Unfortunately, bisect replay
can't receive input directly with the pipe, so it needs to create a temporary intermediate file.)
To make it even easier, you can add an alias to your .bashrc or equivalent:
# bisect undo alias
alias bisectundo="git bisect log | head -n -2 > /tmp/fixed_bisect.log ; git bisect replay /tmp/fixed_bisect.log"
In a new session, you will be able to simply use bisectundo
to go one step back.
If you get an "illegal line count" error for the negative number argument (which is because some implementations of head
don't support it), you can use this longer form, which bases the number of lines to keep on the length of the log using wc
:
git bisect log | head -n $(($(git bisect log | wc -l)-2)) > /tmp/fixed_bisect.log ; git bisect replay /tmp/fixed_bisect.log