{"id":6383,"date":"2014-12-16T17:43:18","date_gmt":"2014-12-16T17:43:18","guid":{"rendered":"http:\/\/livecode.com\/?p=6383"},"modified":"2014-12-16T17:43:18","modified_gmt":"2014-12-16T17:43:18","slug":"using-git-bisect-to-find-a-buggy-commit","status":"publish","type":"post","link":"https:\/\/legacy.livecode.com\/using-git-bisect-to-find-a-buggy-commit\/","title":{"rendered":"Using git bisect to find a buggy commit"},"content":{"rendered":"<p lang=\"en-US\">During the last month I have been switching between translating the IDE to Greek, and refining LC 6.7 and 7.0 releases, in terms of fixing bugs. Some bugs are quite easy to fix. Some others though, can be quite tricky. The first thing to do is locate where the bug comes from, and the next step is to actually fix it. In some cases, tracking down the cause of the bug is not that obvious. However, if you can find a previous version of the code where the bug was not present, then you can use some Git tools to find the specific commit in the history which introduced the bug. You could try to check out each commit, build it, and check if the bug is present or not. Usually there are a large number of commits, so this can take a really long time. This is a linear search. Hopefully, we can do much better by doing a binary search. \u00a0This is where the <span style=\"font-family: 'Courier New', monospace;\"><span style=\"font-size: small;\">git bisect<\/span><\/span> command comes in.<\/p>\n<p lang=\"en-US\"><b>What is git bisect?<\/b><\/p>\n<p>Git bisect is an extremely useful command in the Git version control system. The bisect command does a binary search through your commit history to help you identify which commit introduced an issue. It is quite quick. Imagine that between a working version of the code and a buggy one, there are a few hundreds commits, say N. Using git bisect requires only log(N) steps!<\/p>\n<p><strong>How to use it?<\/strong><\/p>\n<p>1. You start by specifying two states, a bad and a good one. A state can be a commit hash, a branch name, or a tag name:<\/p>\n<p><a style=\"font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px;\" href=\"http:\/\/livecode.com\/wp-content\/uploads\/2014\/12\/code1panos.jpg\"><br \/><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6411\" alt=\"code1panos\" src=\"http:\/\/livecode.com\/wp-content\/uploads\/2014\/12\/code1panos.jpg\" width=\"764\" height=\"93\" \/><\/a><\/p>\n<p>In this example, HEAD is the current revision (ie the bad one), and 6.7.0-dp-6 is a tag of a good revision.<\/p>\n<p>2. We then test it for the presence of the bug. We inform Git if the bug is there by running git bisect good, or git bisect bad:<\/p>\n<p><a href=\"http:\/\/livecode.com\/wp-content\/uploads\/2014\/12\/code2panos.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6409\" alt=\"code2panos\" src=\"http:\/\/livecode.com\/wp-content\/uploads\/2014\/12\/code2panos.jpg\" width=\"765\" height=\"77\" \/><\/a><\/p>\n<p>3. Repeating the same process bring us closer to the faulty commit:<\/p>\n<p><a href=\"http:\/\/livecode.com\/wp-content\/uploads\/2014\/12\/codepanos3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6407\" alt=\"codepanos3\" src=\"http:\/\/livecode.com\/wp-content\/uploads\/2014\/12\/codepanos3.jpg\" width=\"767\" height=\"109\" \/><\/a><\/p>\n<p>4. If we ever arrive at a commit that won&#8217;t build for a known or irrelevant reason, or if we just don&#8217;t know if the specific revision is good or bad, then we simply run git bisect skip. It doesn\u2019t define it as good or bad, picks a neighbor commit and moves on:<\/p>\n<p><a href=\"http:\/\/livecode.com\/wp-content\/uploads\/2014\/12\/codepanos4.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6405\" alt=\"codepanos4\" src=\"http:\/\/livecode.com\/wp-content\/uploads\/2014\/12\/codepanos4.jpg\" width=\"765\" height=\"73\" \/><\/a><\/p>\n<p>5. Voil\u00e0! We fould the commit that introduced the bug!<\/p>\n<p><a href=\"http:\/\/livecode.com\/wp-content\/uploads\/2014\/12\/codepanos5.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6403\" alt=\"codepanos5\" src=\"http:\/\/livecode.com\/wp-content\/uploads\/2014\/12\/codepanos5.jpg\" width=\"765\" height=\"128\" \/><\/a><\/p>\n<p>After finding the problematic commit, we can see the diffs in github, and find out the cause of the bug.<\/p>\n<p>6. We then move back to the HEAD (git bisect reset) and fix the bug!<span style=\"line-height: 18.2000007629395px;\"><br \/><\/span><\/p>\n<p><a href=\"http:\/\/livecode.com\/wp-content\/uploads\/2014\/12\/codepanos6.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6401\" alt=\"codepanos6\" src=\"http:\/\/livecode.com\/wp-content\/uploads\/2014\/12\/codepanos6.jpg\" width=\"767\" height=\"128\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>During the last month I have been switching between translating the IDE to Greek, and refining LC 6.7 and 7.0 releases, in terms of fixing bugs. Some bugs are quite easy to fix. Some others though, can be quite tricky. The first thing to do is locate where the bug comes from, and the next<\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"om_disable_all_campaigns":false,"footnotes":""},"categories":[45],"tags":[],"class_list":["post-6383","post","type-post","status-publish","format-standard","hentry","category-blog"],"acf":[],"_links":{"self":[{"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/posts\/6383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/comments?post=6383"}],"version-history":[{"count":0,"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/posts\/6383\/revisions"}],"wp:attachment":[{"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/media?parent=6383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/categories?post=6383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/legacy.livecode.com\/wp-json\/wp\/v2\/tags?post=6383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}