git bisect for lazy people
This walks the git history down from the current commit to the older commits.
Copy and adapt for your needs.
#!/bin/bash
BRANCH=your_branch
set -euxo pipefail
log_report() {
echo "Error on line $1"
}
trap 'log_report $LINENO' ERR
git switch $BRANCH
git log --oneline | cut -d' ' -f1 | while read hash;
do
echo
echo $hash;
git switch -d $hash
DO_SOMETHING
if YOUR_COMMAND; then
echo "this is good (the commit above this introduced the bug): $hash"
break
fi
git restore .
sleep 1
done
git switch $BRANCH
You need to adapt these parts:
- BRANCH
- DO_SOMETHING
- YOUR_COMMAND: Should return
0if everything is fine. - remove "sleep 1", if you need to walk back a lot of commits.