{"thread":{"id":"13790","subject":"git-merge oddities (or: how to create a one-parent merge)","startedAt":"2008-06-04T12:04:11Z","lastAt":"2008-06-04T12:04:11Z","messageCount":1,"participants":["Karl Hasselström"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"78618","messageId":"20080604120411.GD2126@diana.vm.bytemark.co.uk","threadId":"13790","inReplyTo":null,"subject":"git-merge oddities (or: how to create a one-parent merge)","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-06-04T12:04:11Z","receivedAt":"2008-06-04T12:04:11Z","isPatch":false,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"Consider the following script:\n\ngit init\necho foo >> foo\ngit add foo\ngit commit -m initial\n\ngit checkout -b maint\necho bar >> bar\ngit add bar\ngit commit -m \"bugfix\"\n\ngit checkout master\necho foo2 >> foo\ngit commit -a -m \"development\"\n\ngit checkout -b branch\necho baz >> baz\ngit add baz\ngit commit -m \"feature\"\ngit merge maint\n\ngit checkout master\n#git merge maint && git merge branch\n#git merge branch && git merge maint\n#git merge branch maint\n\ngitk --all\n\nHere we have two branches, \"maint\" and \"branch\", that we want to merge\nto master. Containment-wise, both master and maint are subsets of\nbranch:\n\n   o--A           A: master\n    \\  \\          B: maint\n     \\  \\         C: branch\n      B--C\n\nIf we uncomment the first line, each merge creates a new commit, which\nis what we asked for but not what we wanted:\n\n   o--o--o--A\n    \\  \\/  /\n     \\ /\\ /\n      B--C\n\nSo uncomment the second line instead; now both merges fast-forward,\nand all is well.\n\nI thought I could work around the problem of having to merge in the\nright order by giving git-merge both branches at once, and having it\nrealize that a fast-forward will do. And uncommenting the third line,\nI indeed see that git-merge has avoided creating a three-parent merge\n-- it has correctly realized that maint is a subset of branch.\n\nHowever, it has also realized that master is a subset of branch, and\nskipped that parentage as well. So the resulting merge commit has just\none parent: \"branch\".\n\n   o--o           A: master\n    \\  \\          B: maint\n     \\  \\         C: branch\n      B--C--A\n\nSurely the right thing to do here is to just make it fast-forward to\n\"branch\"?\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"}]}