Slide 1

Slide 1 text

© AND Digital 2023 Luke Stringer, Tech Principal @ AND Digital Debugging with Git

Slide 2

Slide 2 text

© AND Digital 2023

Slide 3

Slide 3 text

© AND Digital 2023 Given some steps to reproduce… Approaches to Debugging 1. Manually look for the problem using • Intuition • Print statements & Breakpoints • Remote logging 2. Find when the bug was introduced

Slide 4

Slide 4 text

© AND Digital 2023 2. Find when the bug was introduced How?

Slide 5

Slide 5 text

© AND Digital 2023 Use your Git history

Slide 6

Slide 6 text

598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b

Slide 7

Slide 7 text

Bug! 598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b

Slide 8

Slide 8 text

Bug! 598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b Find the commit where the bug was introduced • What changed • Why it was changed • Who changed it

Slide 9

Slide 9 text

© AND Digital 2023 $ git bisect • Automates the process using a binary search. • Very ef fi cient; worst case scenario O(log n) • 10 commits takes 4 steps. log2(10) • 100 commits takes 7 steps. log2(100) • 1000 commits takes 10 steps. log2(10)

Slide 10

Slide 10 text

© AND Digital 2023 $ git bisect • You provide 2 control points: • A “good” commit, e.g. bug absent • A “bad” commit, e.g. bug present Bad Good

Slide 11

Slide 11 text

598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b © AND Digital 2023

Slide 12

Slide 12 text

598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b

Slide 13

Slide 13 text

598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b $ git bisect start

Slide 14

Slide 14 text

Bad 598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b $ git bisect start $ git bisect bad

Slide 15

Slide 15 text

Bad 598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b $ git bisect start $ git bisect bad $ git bisect good 598fde5
 Good

Slide 16

Slide 16 text

Bad 598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b $ git bisect start $ git bisect bad $ git bisect good 598fde5
 Bisecting: 4 revisions left 
 to test after this 
 (roughly 2 steps) [6f5e527] Good

Slide 17

Slide 17 text

Bad 598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b $ git bisect start $ git bisect bad $ git bisect good 598fde5
 Bisecting: 4 revisions left 
 to test after this 
 (roughly 2 steps) [6f5e527] $ git bisect bad
 Good

Slide 18

Slide 18 text

Bad 598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b $ git bisect start $ git bisect bad $ git bisect good 598fde5
 Bisecting: 4 revisions left 
 to test after this 
 (roughly 2 steps) [6f5e527] $ git bisect bad
 Bisecting: 2 revisions left 
 to test after this 
 (roughly 1 step) [97b914a] Good

Slide 19

Slide 19 text

Bad 598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b $ git bisect start $ git bisect bad $ git bisect good 598fde5
 Bisecting: 4 revisions left 
 to test after this 
 (roughly 2 steps) [6f5e527] $ git bisect bad
 Bisecting: 2 revisions left 
 to test after this 
 (roughly 1 step) [97b914a] $ git bisect good
 Good

Slide 20

Slide 20 text

Bad 598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b $ git bisect start $ git bisect bad $ git bisect good 598fde5
 Bisecting: 4 revisions left 
 to test after this 
 (roughly 2 steps) [6f5e527] $ git bisect bad
 Bisecting: 2 revisions left 
 to test after this 
 (roughly 1 step) [97b914a] $ git bisect good
 Bisecting: 0 revisions left 
 to test after this 
 (roughly 1 step) [40081db] Good

Slide 21

Slide 21 text

Bad 598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b $ git bisect start $ git bisect bad $ git bisect good 598fde5
 Bisecting: 4 revisions left 
 to test after this 
 (roughly 2 steps) [6f5e527] $ git bisect bad
 Bisecting: 2 revisions left 
 to test after this 
 (roughly 1 step) [97b914a] $ git bisect good
 Bisecting: 0 revisions left 
 to test after this 
 (roughly 1 step) [40081db] $ git bisect good
 Good

Slide 22

Slide 22 text

Bad 598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3 7aba54b $ git bisect start $ git bisect bad $ git bisect good 598fde5
 Bisecting: 4 revisions left 
 to test after this 
 (roughly 2 steps) [6f5e527] $ git bisect bad
 Bisecting: 2 revisions left 
 to test after this 
 (roughly 1 step) [97b914a] $ git bisect good
 Bisecting: 0 revisions left 
 to test after this 
 (roughly 1 step) [40081db] $ git bisect good
 6f5e527 is the first bad commit
 commit 6f5e527
 Author: Luke Stringer
 Date: Sat Mar 31
 
 Add user config Good First Bad commit

Slide 23

Slide 23 text

© AND Digital 2023 For Best Results • Have a clear de fi nition of good & bad • You can supply a script to git bisect to check if criteria is met • Keep commits small (enough) to inspect • Write descriptive commit messages to aid understanding © AND Digital 2023

Slide 24

Slide 24 text

© AND Digital 2023 🐛 Luke Stringer, Tech Principal @ AND Digital Debugging with Git