git for debugging (a.k.a code archaeology)

Post on 17-Aug-2015

77 Views

Category:

Presentations & Public Speaking

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Git for debugging

Riaan Cornelius

a.k.a Code archaeology

TopicsBecause nobody likes a surprise

2

• Code Archaeology• Git Blame• Git log• Pickaxe• Git show

• Example: Jenkins• Debugging with git bisect• Automating git bisect

• Bitbucket code review

Code ArchaeologyUncovering the history of your code

3

• All code is always documented.

• Separating the interesting commits from the uninteresting ones.

• Git has tools to make this easier.

Code ArchaeologyUncovering the history of your code

4

Git blameAnnotates each line in the given file with information from the revision which last modified the line.

With -w, blame ignores lines where only whitespace changed.With -M, blame detects moved or copied lines within a file.With -C, blame extends this move or copy detection to other files that were modified in the same commit.

Code ArchaeologyUncovering the history of your code

5

Git logShows the commit logs.

With --date=short shows only the date, but not the time, in YYYY-MM-DD format.With --graph draws a text-based graphical representation of the commit history on the left hand side of the output. With --pretty you can specify a format.

Code ArchaeologyUncovering the history of your code

6

PickaxeFor Detecting Addition/Deletion of Specified String. Actually a git log param: -S‘<block of text>’

When used with --pickaxe-regex, treat the <block of text> as an extended POSIX regular expression to match, instead of a literal string.

Code ArchaeologyUncovering the history of your code

7

Git showFor commits it shows the log message and textual diff.

When used with --quiet, Don’t show the diff.With --pretty you can specify a format.

ExampleJenkins

8

Uncovering some of Jenkin’s history

Why do we need a Jenkins repoWho wrote that code?

9

Git blameWho wrote that code?

10

Git showWhat info can we get from the commit?

11

Git blameWho wrote that code?

12

Git showWhat info can we get from the commit?

13

PickaxeDigging deeper

14

Git logSeeing the bigger picture

15

git log

Git logSeeing the bigger picture

16

Git logSeeing the bigger picture

17

git log --graph --abbrev-commit --pretty=format:'%Cred%h%Creset –%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'

Git logMaking it prettier

18

Git logAdvanced use case - churn

19

git log --all -M -C --name-only --format='format:' "$@" | sort | grep -v '^$' | uniq -c | sort | awk 'BEGIN {print "count\tfile"} {print $1 "\t" $2}' | sort -g

Git bisectHunting down bugs

20

Git BisectFind by binary search the change that introduced a bug.

Simple process:• Git bisect start <BAD> <GOOD>• Git bisect good | bad• Repeat until first bad commit found• Git bisect reset

Git bisectHunting down bugs

21

Simple example.

After a night of drunken coding, the main.java file is missing. Find out what happened.

Git bisectHunting down bugs

22

Git bisectHunting down bugs

23

Git bisectHunting down bugs

24

Git bisect (automated)Hunting down bugs the easy way

25

How do we automate this.

Essentially same steps as previously, but we write a test script to determine whether the commit is good or bad.

• Git bisect start <BAD> <GOOD>• Git bisect run <TEST SCRIPT>• Wait for bad commit to be found• Git bisect reset

Git bisect (automated)Hunting down bugs the easy way

26

Git bisect (automated)Hunting down bugs the easy way

27

Bitbucket peer reviewWhy?

28

Why peer review?

• Improved code quality.• Knowledge transfer.

Bitbucket peer reviewWhy?

29

We know we should do it, but polls consistently show only about 50% of teams peer review.

Bitbucket peer reviewHow?

30

Bitbucket peer reviewHow?

31

Bitbucket peer reviewHow?

32

In closingWhat should you take from this?

33

Code archaeology• All code is always documented

Learn to use Git more productively• Git blame• Git log• Pickaxe

• Git show• Third party extensions• So many others!

Do peer reviews!

34

Questions?

References:

Git man pages: http://git-scm.com/docsCode Archaeology: http://jfirebaugh.github.com/blog/2012/03/07/code-archaeology-with-gitGit tutorial: http://www.vogella.com/tutorials/Git/article.html

XKCD References you might have noticed (Less useful, but definitely more amusing)Ballmer peak: https://xkcd.com/323/Commit messages: https://xkcd.com/1296/

top related