A Real 'git bisect' Session

Now that you understand a bisect session, you’re going to embed this idea by running through an actual git bisect session. If the previous lesson felt a bit abstract, then this might help make the lesson more vivid.

Requirements

What you’re going to do is create a Git repository with one file (projectfile). In this file, you are going to add a line for each commit. The first line will be 1, the second 2, and so on until the hundredth commit, which adds the line 100.

In this scenario, the “bug” is the line 63, but you don’t know that yet. All you know is that you can tell if the bug is in the code with this shell command:

if grep -w 63 projectfile
> then
>   echo BAD
> else
>   echo GOOD

It outputs BAD if the “bug” is found and GOOD if it is absent. Obviously, this is an arbitrary example. Your reproduction code for a bug in a real situation might be far more complicated and/or time-consuming.

Implementation

Type this in:

1	mkdir -p lgthw_bisect
2	cd lgthw_bisect
3	git init
4	touch projectfile
5	git add projectfile
6	cat > test.sh << END
7	> if grep 63 projectfile
8	> then
9	>   echo BAD
10	> else
11	>   echo GOOD
12	> fi
13	> END
14	chmod +x test.sh
15	git add test.sh

Get hands-on with 1200+ tech skills courses.