{"thread":{"id":"40986","subject":"query regarding git merge","startedAt":"2015-12-13T17:55:59Z","lastAt":"2015-12-14T21:13:21Z","messageCount":4,"participants":["rohit gupta","brian m. carlson","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"274352","messageId":"loom.20151213T185500-631@post.gmane.org","threadId":"40986","inReplyTo":null,"subject":"query regarding git merge","fromName":"rohit gupta","fromEmail":"roborohitgupta75@gmail.com","sentAt":"2015-12-13T17:55:59Z","receivedAt":"2015-12-13T17:55:59Z","isPatch":false,"sender":{"key":"roborohitgupta75@gmail.com","avatar":null},"body":"Hi,\nI am confused with git merge working.\n\nSuppose I have these 3 files in master branch-\na.txt\nb.txt\nd.txt\n\nI create a branch, add c.txt to it and commit. So its final contents \nare-\na.txt\nb.txt\nc.txt\nd.txt\n\nThen, I checkout master branch, delete a.txt, add e.txt and commit. So \nfinal contents are-\nb.txt\nd.txt\ne.txt\n\nNow when I merge branch in master,\nits result is-\nb.txt\nc.txt\nd.txt\ne.txt\n\nNow suppose in branch, a.txt was needed for its working. And in master \nbranch's latest commit a.txt was removed because maybe it wasn't needed \nor it was introducing bugs.\nNow, git merge removes that a.txt\nSo now branch functionality wouldn't work. \nIsn't that wrong??\n"},{"id":"274354","messageId":"20151213181800.GK990758@vauxhall.crustytoothpaste.net","threadId":"40986","inReplyTo":"loom.20151213T185500-631@post.gmane.org","subject":"Re: query regarding git merge","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-12-13T18:18:00Z","receivedAt":"2015-12-13T18:18:00Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sun, Dec 13, 2015 at 05:55:59PM +0000, rohit gupta wrote:\n> Hi,\n> I am confused with git merge working.\n> \n> Suppose I have these 3 files in master branch-\n> a.txt\n> b.txt\n> d.txt\n> \n> I create a branch, add c.txt to it and commit. So its final contents\n> are-\n> a.txt\n> b.txt\n> c.txt\n> d.txt\n> \n> Then, I checkout master branch, delete a.txt, add e.txt and commit. So\n> final contents are-\n> b.txt\n> d.txt\n> e.txt\n> \n> Now when I merge branch in master,\n> its result is-\n> b.txt\n> c.txt\n> d.txt\n> e.txt\n> \n> Now suppose in branch, a.txt was needed for its working. And in master\n> branch's latest commit a.txt was removed because maybe it wasn't needed\n> or it was introducing bugs.\n> Now, git merge removes that a.txt\n> So now branch functionality wouldn't work.\n> Isn't that wrong??\n\nInstead of thinking of Git as merging two sets of files, think of it as\nmerging two sets of changes.  Git computes a merge base based on one or\nmore ancestors of both branches.  During a merge, Git takes the\ndifferences on each side and combines them.  Logically, if a change is\nmade on one side but not the other, it will be preserved in the merge.\n\nSo in your case, you deleted a.txt on one side and did not modify it on\nthe other.  Git applied that change to the result of the merge.  Git has\nno way of knowing that a.txt is still required in the result.\n\nThis is a very common question that comes up in a variety of different\nforms.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"},{"id":"274358","messageId":"20151213192316.GM990758@vauxhall.crustytoothpaste.net","threadId":"40986","inReplyTo":"CAGkBSDLMCZR=qrXJKTgpzGGQdogXHN+0Ub8qW=aPq80RjjN=5w@mail.gmail.com","subject":"Re: query regarding git merge","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-12-13T19:23:17Z","receivedAt":"2015-12-13T19:23:17Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"[Please don't top-post.]\n\nOn Mon, Dec 14, 2015 at 12:03:18AM +0530, Rohit Gupta wrote:\n> Thanks brian. I understood my mistake in understanding the working of git\n> merge.\n> But isn't it wrong? As after merging, branch's logic can't work. How to get\n> that right then ?\n\nIf you know that the merge didn't go the way you wanted, you can either\nadd a follow-up commit, or you can do \"git commit --amend\" on the merge\nafter making the necessary changes.  In such a case, it may be useful to\nadd a note to the commit message stating that you modified it from the\noriginal merge.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"},{"id":"274432","messageId":"20151214211320.GE14788@sigill.intra.peff.net","threadId":"40986","inReplyTo":"20151213192316.GM990758@vauxhall.crustytoothpaste.net","subject":"Re: query regarding git merge","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-12-14T21:13:21Z","receivedAt":"2015-12-14T21:13:21Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Dec 13, 2015 at 07:23:17PM +0000, brian m. carlson wrote:\n\n> On Mon, Dec 14, 2015 at 12:03:18AM +0530, Rohit Gupta wrote:\n> > Thanks brian. I understood my mistake in understanding the working of git\n> > merge.\n> > But isn't it wrong? As after merging, branch's logic can't work. How to get\n> > that right then ?\n> \n> If you know that the merge didn't go the way you wanted, you can either\n> add a follow-up commit, or you can do \"git commit --amend\" on the merge\n> after making the necessary changes.  In such a case, it may be useful to\n> add a note to the commit message stating that you modified it from the\n> original merge.\n\nAnd a fundamental takeaway here is that git-merge can only find\n_textual_ conflicts. It is up to the user to determine that the merge\ndidn't introduce any _semantic_ conflicts. For example, by building and\ntesting the result, which is out of git's scope.\n\n-Peff\n"}]}