
{"id":2419,"date":"2017-06-15T23:12:35","date_gmt":"2017-06-16T03:12:35","guid":{"rendered":"http:\/\/www.ikriv.com\/blog\/?p=2419"},"modified":"2017-06-15T23:12:35","modified_gmt":"2017-06-16T03:12:35","slug":"the-confusing-world-of-git-merge-options","status":"publish","type":"post","link":"https:\/\/ikriv.com\/blog\/?p=2419","title":{"rendered":"The confusing world of Git merge options"},"content":{"rendered":"<p>The default git merge is usually all you need, but if you have to deep deeper, you&#8217;ll find that git merge command has very weird looking and confusing options.<\/p>\n<p>I created\u00a0https:\/\/github.com\/ikriv\/merges repository that shows the result of applying different variants of git merge command.<\/p>\n<p>For starters,\u00a0<code>git merge -s ours xyz<\/code>\u00a0is not the same as\u00a0<code>git merge -X ours xyz<\/code>. The first uses merge\u00a0<em>strategy<\/em> called &#8220;ours&#8221;, and the second uses default &#8216;recursive&#8217; merge strategy, but with &#8220;ours&#8221; <em>option<\/em>.\u00a0Creating two entities named &#8220;ours&#8221; that do similar, but subtly different things is the epitome of \u00a0bad interface design.<\/p>\n<p>The &#8220;-s&#8221; variant creates a commit that merges current branch and &#8220;xyz&#8221;, but ignores\u00a0<em>all\u00a0<\/em>changes from xyz, so the resulting content would be identical to the current branch. This is useful for getting rid of unwanted branches when force-pushes and deletes are disabled. The &#8220;-X&#8221; variant only ignores changes from xyz that <em>cause a conflict<\/em>. Changes from xyz that do not cause a conflict\u00a0<em>will\u00a0be included\u00a0<\/em>in the end result.<\/p>\n<p>Similarly, git has\u00a0<code>git merge -X theirs xyz<\/code>, which will merge current branch and xyz, but will ignore changes from the current branch that cause a conflict and will takes those from xyz instead.<\/p>\n<p>Git annoyingly lacks\u00a0<code>git merge -s theirs xyz<\/code>, which would merge current branch with xyz and make the result identical to xyz. This would be <em>very<\/em> useful to simulate force pushes, but alas. I naively tried to use\u00a0<code>git merge -X theirs xyz<\/code>\u00a0instead and got into hot water.<\/p>\n<p>&#8220;Theirs&#8221; merge strategy that ignores the current branch can be simulated by creating a temporary branch and using &#8220;ours&#8221; strategy on it, but why do we need to jump through those hoops?<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The default git merge is usually all you need, but if you have to deep deeper, you&#8217;ll find that git merge command has very weird looking and confusing options. I <a href=\"https:\/\/ikriv.com\/blog\/?p=2419\" 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":[4],"tags":[],"class_list":["entry","author-ikriv","post-2419","post","type-post","status-publish","format-standard","category-hack"],"_links":{"self":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2419","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=2419"}],"version-history":[{"count":2,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2419\/revisions"}],"predecessor-version":[{"id":2421,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2419\/revisions\/2421"}],"wp:attachment":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}