class: center, middle # Advanced debugging with git ## (or simply: git unfuck) --- class: center, middle, .left # It’s all about: 1. git bisect 2. git blame 3. git cherry-pick --- # Pelican - our test project __(It’s actually a pretty neat Python powered static site generator with support for Markdown and reST)__ ## Done so far: 1. Clone the repository from GitHub. 2. Create a new branch to add features 3. Break the code (since I want to show you have to find the fuckup) .center[![](git1.png)] --- # git bisect - Introducion ## When to use? * Your build is somehow broken and you have no clue why ## What does it? * `git bisect` can automatically crawl your commits and will show you, where the (first) build-breaker was introduced ## What do we have to know? * A (healthy|good) commit from which git starts to look for a failure --- # git bisect - Usage 1. Mark the last known good commit: `git bisect start HEAD e35ca1d` .left[![](git2.png)] * `HEAD` is where the build fails. * `e35ca1d` ist the last known healthy commit. This can be a commit, a branch or a tag 2. Let `git bisect` run the the build automatically: `git bisect run ../buildtestscript.sh` * `buildtestscript.sh` runs the build or the part of the build, which breaks the build. The script should be outside the `git` repository. .left[![](git6.png)] (buildtestscript.sh only calls `python setup.py install` because this seems to break the build process) --- # git bisect - Output .left[![](git3.png)] `git bisect` creates a temp-branch and succesfully blamed the bad commit .left[![](git4.png)] Now you know where the bug was introduced :) --- # git blame - Who fucked up? Because it’s nice to know, who introduced the problem, `git` offers you all the tools to `blame` the commiter. `git blame` can tell you who made the last change for each LoC: .left[![](git5.png)] Now you know who will need to pay your next lunch :) --- # Last but not least: git cherry-pick `git cherry-pick` does exactly the thing you think. Image you have fixed a bug in a branch, which was not merged to `master`. You can simply run: .center[``` git cherry-pick ${commit} ```] and the commit will automatically be `merged` into your current branch. :) --- # Wait. There is more: git whatchanged `git whatchanged` is able to tell you, what changed when. Example: You see that a change on ${DATE} made an unwandet change, but you have no clue what was changed - but you know the day it was changed. You can simply run: .center[``` git whatchanged --since="9 day ago" --until="6 day ago" -p lib/aws.lib ```] and `git` will tell you what changed during this period of time: .left[![](git7.png)] --- class: center, middle, .left .center[ #That’s all I blogged about this stuff. Check my Confluence-Page (https://projects.razorfish.de/confluence/pages/viewrecentblogposts.action?key=~janmuell) Everything is hosted on Github: * Presentation: http://janaurka.github.io/git-debug-presentiation * Repo: https://github.com/janaurka/git-debug-presentiation ]