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

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

F2f1f1c0e4be267e6e330d6ecdfaf285?s=128

Luke Stringer

March 02, 2019
Tweet

Transcript

  1. Luke Stringer - @lukestringer90 Debugging with Git

  2. Given some steps to reproduce… 1. Manually look for the

    problem using • Print statements • Breakpoints • Remote logging 2. Find when the bug was introduced Approaches to Debugging
  3. 2. Find when the bug was introduced How?

  4. None
  5. Use your Git history

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

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

    b054ee3 7aba54b
  8. 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
  9. $ git bisect • Automates the process using a binary

    search. • 10 commits takes 4 steps • 100 commits takes 7 steps • You provide two control points. • A “good” commit, e.g. bug absent • A “bad” commit, e.g. bug present
  10. 598fde5 62d017b 97b914a 13f01c7 40081db 6f5e527 eb2c86b f89d7b3 579acfa b054ee3

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

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

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

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

    b054ee3 7aba54b $ git bisect start $ git bisect bad $ git bisect good 598fde5
 Good
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. For Best Results • Have a clear definition of good

    & bad • 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