{"thread":{"id":"35264","subject":"Question on merge order","startedAt":"2013-11-02T01:11:55Z","lastAt":"2013-11-02T02:22:29Z","messageCount":2,"participants":["Gerasimos Dimitriadis","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"230026","messageId":"CAM3f4mDXwXTJ5Kq3sgyK7yDLsBTdxSJXkZdE-SBe2LqfM3fccw@mail.gmail.com","threadId":"35264","inReplyTo":null,"subject":"Question on merge order","fromName":"Gerasimos Dimitriadis","fromEmail":"gedimitr@gmail.com","sentAt":"2013-11-02T01:11:55Z","receivedAt":"2013-11-02T01:11:55Z","isPatch":false,"sender":{"key":"gedimitr@gmail.com","avatar":null},"body":"Hi,\n\nI have a question on the order with which commits are applied on a merge.\n\nI am merging two branches that have changes on the same text file and\nI'd like to ask you about the merge result.\n\nThe following output is provided on the two branches to be merged, by\nthe command:\ngit show-branch --date-order branchA branchB\n\n! [branchA] file.txt got form A\n * [branchB] file.txt got form B\n--\n+  [branchA] file.txt got form A\n * [branchB] file.txt got form B\n+  [branchA^] file.txt got form B\n+* [branchA~2] First version of file.txt (form A)\n\nNow, this text file alternates between the following contents:\n\nAccording to form A, file.txt contains only one line of text:\nGerasimos\n\nAccording to form B, file.txt contains three lines of text:\nPL-3\nPL-4\nPL-5\n\nThe merge is done with the following commands:\ngit checkout branchA\ngit merge branchB\n\nNow, the result of the merge gets file.txt to form B, i.e. it contains\nthe above 3 lines of text.\nMy question is, why does the merge have the file resolve to form B and\nnot to form A ?\nTheoretically, the merge could resolve to either A or B form. If the\ndate is taken into account, maybe the A\ncould even appear to be a better result.\n\nThank you in advance and BRs,\nGerasimos\n"},{"id":"230027","messageId":"20131102022229.GH41460@vauxhall.crustytoothpaste.net","threadId":"35264","inReplyTo":"CAM3f4mDXwXTJ5Kq3sgyK7yDLsBTdxSJXkZdE-SBe2LqfM3fccw@mail.gmail.com","subject":"Re: Question on merge order","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2013-11-02T02:22:29Z","receivedAt":"2013-11-02T02:22:29Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sat, Nov 02, 2013 at 03:11:55AM +0200, Gerasimos Dimitriadis wrote:\n> Hi,\n> \n> I have a question on the order with which commits are applied on a merge.\n> \n> I am merging two branches that have changes on the same text file and\n> I'd like to ask you about the merge result.\n> \n> The following output is provided on the two branches to be merged, by\n> the command:\n> git show-branch --date-order branchA branchB\n> \n> ! [branchA] file.txt got form A\n>  * [branchB] file.txt got form B\n> --\n> +  [branchA] file.txt got form A\n>  * [branchB] file.txt got form B\n> +  [branchA^] file.txt got form B\n> +* [branchA~2] First version of file.txt (form A)\n> \n> Now, this text file alternates between the following contents:\n> \n> According to form A, file.txt contains only one line of text:\n> Gerasimos\n> \n> According to form B, file.txt contains three lines of text:\n> PL-3\n> PL-4\n> PL-5\n> \n> The merge is done with the following commands:\n> git checkout branchA\n> git merge branchB\n> \n> Now, the result of the merge gets file.txt to form B, i.e. it contains\n> the above 3 lines of text.\n> My question is, why does the merge have the file resolve to form B and\n> not to form A ?\n> Theoretically, the merge could resolve to either A or B form. If the\n> date is taken into account, maybe the A\n> could even appear to be a better result.\n\nI'm going to try to explain this, but I might be wrong, and I'm sure\nsomeone will correct me if I am.  git computes a merge base from the two\nbranches, and that commit is branchA~2.  Now, the net change in branchA\nis nothing; that is, the file is exactly the same at the merge base as\nit is at the final commit of branchA.  branchB, on the other hand, has\nmade a change, to form B.\n\ngit only considers three points here: the merge base and the two\nbranches being merged.  So since there is a change on branchB, but no\nchange on branchA, git applies the changes introduced by branchB, and\nyou get form B, since a merge applies the changes in both branches.  The\ntrivial case where a change has been made in one branch but not the\nother means that change is applied.  git doesn't care about intermediate\nchanges here, since it doesn't consider them.\n\nIn some cases, git can consider multiple common ancestors when using the\ndefault recursive strategy, but that doesn't apply here.\n\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"}]}