Lazy Git Bisect

A lot of times, especially during an incident, you want to run git bisect, but often finding a "good" commit is a challenge. I would rather just drop a date into git when I new things were working and deal with a few extra steps during the bisect.

I put these bash functions together to provide that functionality.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# call like `bisect_time "2022-07-01"` or just
# `bisect_time` to use yesterday's date
function bisect_time {
    since=${1:-$(date -d yesterday '+%Y-%m-%d')}
    good=$(git log --since="$since" --reverse --format="%H" | head -n 1)
    echo "HEAD is bad"
    echo "$good is good"
    git bisect start HEAD $good
    echo "use git bisect good/bad to mark commits"
}

# call like `bisect_time_with_test ./test.sh "2022-07-01"` or just
# `bisect_time_with_test ./test.sh` to use yesterday's date
function bisect_time_with_test {
    bisect_time "$2"
    git bisect run "$1"
}

2022-10-08