
{"id":2480,"date":"2018-07-04T17:33:30","date_gmt":"2018-07-04T21:33:30","guid":{"rendered":"https:\/\/ikriv.com\/blog\/?p=2480"},"modified":"2018-07-04T17:33:30","modified_gmt":"2018-07-04T21:33:30","slug":"git-remember-to-use-no-ff-when-merging-feature-branch-to-master","status":"publish","type":"post","link":"https:\/\/ikriv.com\/blog\/?p=2480","title":{"rendered":"Git: remember to use &ndash;&ndash;no-ff when merging feature branch to master"},"content":{"rendered":"<p>A few days ago I ran into a situation when I forgot to add <code>--no-ff<\/code> when merging a feature branch into master. The result was a mess.<\/p>\n<p>State before the final merge:<br \/>\n<img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"161\" src=\"https:\/\/ikriv.com\/blog\/wp-content\/uploads\/2018\/07\/before_merge.png\" alt=\"Before merge\" class=\"alignnone size-full wp-image-2481\" \/><\/p>\n<p>State after switching to master and doing <code>git merge feature<\/code> (bad state!):<br \/>\n<img loading=\"lazy\" decoding=\"async\" width=\"485\" height=\"156\" src=\"https:\/\/ikriv.com\/blog\/wp-content\/uploads\/2018\/07\/badcase3.png\" alt=\"merge without --no-ff\" class=\"alignnone size-full wp-image-2485\" \/><\/p>\n<p>State after donig <code>git merge --no-ff feature<\/code> instead (good state):<br \/>\n<img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"177\" src=\"https:\/\/ikriv.com\/blog\/wp-content\/uploads\/2018\/07\/goodcase3.png\" alt=\"merge with --no-ff\" class=\"alignnone size-medium wp-image-2486\" \/><\/p>\n<p>The flow of events was as follows:<\/p>\n<ol>\n<li>Create &#8216;feature&#8217; branch off master<\/li>\n<li>Add some commits to feature and to master<\/li>\n<li>Merge latest master into feature to resolve any conflicts<\/li>\n<li>Work on the feature a little more<\/li>\n<\/ol>\n<p>Now the feature is ready to be merged back into master. Since &#8220;feature&#8221; has all commits that &#8220;master&#8221; has plus some more, git by default will simply fast-forward &#8220;master&#8221; to be the same as &#8220;feature&#8221;, and the feature branch will effectively befcome the new master. It does not look good: feature and master commits are now mixed in the main branch line. The annoying part is that if it has already been pushed to origin, it is not easy to fix without force-pushes, and force-pushes are not always enabled. The end result is that you get very confusing commit history for the rest of the life of the project.<\/p>\n<p>If you do use <code>--no-ff<\/code>, the history is preserved much better: all feature commits are kept in a side branch and only the merge is in the main line.<\/p>\n<p><a href=\"https:\/\/ikriv.com\/blog\/wp-content\/uploads\/2018\/07\/branchdemo.bat_.txt\">Click to download the batch file that demonstrates the problem<\/a> (rename from .txt. It creates the &#8220;bad&#8221; case by default. Pass it <code>--no-ff<\/code> argument to create history without fast forward.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few days ago I ran into a situation when I forgot to add &#8211;no-ff when merging a feature branch into master. The result was a mess. State before the <a href=\"https:\/\/ikriv.com\/blog\/?p=2480\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[1],"tags":[],"class_list":["entry","author-ikriv","post-2480","post","type-post","status-publish","format-standard","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2480"}],"version-history":[{"count":13,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2480\/revisions"}],"predecessor-version":[{"id":2499,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2480\/revisions\/2499"}],"wp:attachment":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}