Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Debugging with Git

Debugging with Git

Lightning talk on how to use git bisect to debug your code. Presented at
• DDDNorth 2019,
• dotnetsheff June 4th 2019
• UIKonf (remotely) May 18th 2020
• Sky Betting & Gaming Engineering Conference Feb 2023

For more info see here:
https://git-scm.com/docs/git-bisect

Luke Stringer

March 02, 2019
Tweet

More Decks by Luke Stringer

Other Decks in Programming

Transcript

  1. © 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
  2. 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
  3. © 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)
  4. © 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
  5. Bad 598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa

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

    b054ee3 7aba54b $ git bisect start $ git bisect bad $ git bisect good 598fde5
 Good
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. © 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