{"id":14867,"date":"2016-06-17T12:16:40","date_gmt":"2016-06-17T16:16:40","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=14867"},"modified":"2016-06-17T12:16:40","modified_gmt":"2016-06-17T16:16:40","slug":"git-2-9s-diff-compactionheuristic","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/06\/17\/git-2-9s-diff-compactionheuristic\/","title":{"rendered":"Git 2.9&rsquo;s diff.compactionHeuristic"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/blog\/2188-git-2-9-has-been-released\">Git<\/a> (via <a href=\"https:\/\/news.ycombinator.com\/item?id=11915287\">Hacker News<\/a>):<\/p>\n<blockquote cite=\"https:\/\/github.com\/blog\/2188-git-2-9-has-been-released\"><p>If you&rsquo;ve used Git, you&rsquo;ve probably looked at a lot of diffs. Most of the time the diff shows exactly what you did: changed some lines, added some new ones, or took some away. But because Git generates the diff only from seeing the &ldquo;before&rdquo; and &ldquo;after&rdquo; states of your files, sometimes the way it shows the changes can be pretty confusing.<\/p><p>[&#8230;]<\/p><p>The author probably didn&rsquo;t write the loop as two out-of-order halves. But because the outer lines of the old and new loops are the same, it&rsquo;s equally valid to attribute the lines either way (it&rsquo;s tempting to say that the problem can be solved by always starting the added lines at the top, but that only fixes this case; you&rsquo;d have the opposite problem if the new loop were added after the old).<\/p><p>In 2.9, Git&rsquo;s diff engine learned a new heuristic: it tries to keep hunk boundaries at blank lines, shifting the hunk &ldquo;up&rdquo; whenever the bottom of the hunk matches the bottom of the preceding context, until we hit a blank line.<\/p><\/blockquote>\n<p>It&rsquo;s experimental, so you have to enable <code>diff.compactionHeuristic<\/code> with <tt>git config<\/tt>. Xcode 7.3.1 comes with Git 2.7.4, and the Xcode 8 beta comes with 2.8.1.<\/p>","protected":false},"excerpt":{"rendered":"<p>Git (via Hacker News): If you&rsquo;ve used Git, you&rsquo;ve probably looked at a lot of diffs. Most of the time the diff shows exactly what you did: changed some lines, added some new ones, or took some away. But because Git generates the diff only from seeing the &ldquo;before&rdquo; and &ldquo;after&rdquo; states of your files, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[2],"tags":[377,376,226],"class_list":["post-14867","post","type-post","status-publish","format-standard","hentry","category-technology","tag-git","tag-versioncontrol","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14867","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=14867"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14867\/revisions"}],"predecessor-version":[{"id":14868,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14867\/revisions\/14868"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=14867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=14867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=14867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}