{"thread":{"id":"44270","subject":"RE: git merge deletes my changes","startedAt":"2016-10-10T16:53:59Z","lastAt":"2016-10-12T09:27:46Z","messageCount":4,"participants":["Eduard Egorov","Paul Smith","Jakub Narębski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"303733","messageId":"AM4PR03MB1636EA0DEB4C8095F04AB92ADBDB0@AM4PR03MB1636.eurprd03.prod.outlook.com","threadId":"44270","inReplyTo":"AM4PR03MB1636BE3423E2BC4F0E998159DBDB0@AM4PR03MB1636.eurprd03.prod.outlook.com","subject":"RE: git merge deletes my changes","fromName":"Eduard Egorov","fromEmail":"eduard.egorov@icl-services.com","sentAt":"2016-10-10T10:19:47Z","receivedAt":"2016-10-10T16:53:59Z","isPatch":false,"sender":{"key":"eduard.egorov@icl-services.com","avatar":null},"body":"Hello again,\n\nI've noticed that my git is quite old (1.8.3) and built it from source tarball (2.10.1). Now the output is:\n\n# ~/gitbuild/git-2.10.1/git merge -s subtree --squash ceph_ansible\nfatal: refusing to merge unrelated histories\n\nI've checked my command history again:\n  738  git rm -rf ceph-ansible/\n  739  ll\n  740  ll ceph-ansible/\n  741  rm ceph-ansible/purge_ceph_cluster.yml \n  742  git read-tree --prefix=ceph-ansible/ -u ceph_ansible\n  743  gs\n  744  gc \"ceph-ansible: reset repo state\"\n\nA quick googling showed (http://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories ) that the default behavior is changed. Adding ' --allow-unrelated-histories' clears the error message but the merge itself is still wrong (my changes are lost). \n\nThis error message might explain why git can't merge it correctly (since these repos doesn't has any relations, right). Can somebody confirm this please? Doesn't \"merge -s subtree\" really merges branches?\n\nWith best regards\nEduard Egorov\n\n-----Original Message-----\nFrom: Eduard Egorov \nSent: Monday, October 10, 2016 12:39 PM\nTo: 'git@vger.kernel.org' <git@vger.kernel.org>\nSubject: git merge deletes my changes\n\nHello Git experts,\n\nA week ago, I've reset a state of 'ceph-ansible' folder in %current% branch with code from corresponding branch (that tracks an upstream from github):\n\n# git read-tree --prefix=ceph-ansible/ -u ceph_ansible\n\nThen I've committed several changes, including:\n\n1. Renamed file and commited:\n# git mv site.yml.sample site.yml\n\n2. Made some changes and committed\n\n3. Pulled updates from original branch by:\n# git merge -s subtree --squash ceph_ansible\n\nIt said:\n    Auto-merging ceph-ansible/site.yml.sample\n    blablabla\n    Squash commit -- not updating HEAD\n    Automatic merge went well; stopped before committing as requested\n\nI can see that \"my\" ceph-ansible/site.yml is deleted (as well as few new files added by me), ceph-ansible/site.yml.sample is restored and doesn't contain my changes (it's just restored to the state before my changes).\n`git log ceph_ansible site.yml.sample` shows the latest change on ceph_ansible branch done from 26th of August, 2016, my changes in %current% branch was this October, so it shouldn't be any conflict either (even if it was).\nI believe there is some obvious explanation for this behavior. Could you help me please? What information can  I provide in order to troubleshoot this issue? \n\nA post on SO: http://stackoverflow.com/questions/39954265/git-merge-deletes-my-changes\n\nWith best regards\nEduard Egorov\n\n\n"},{"id":"303768","messageId":"1476121942.15746.99.camel@mad-scientist.net","threadId":"44270","inReplyTo":"AM4PR03MB1636EA0DEB4C8095F04AB92ADBDB0@AM4PR03MB1636.eurprd03.prod.outlook.com","subject":"Re: git merge deletes my changes","fromName":"Paul Smith","fromEmail":"paul@mad-scientist.net","sentAt":"2016-10-10T17:52:22Z","receivedAt":"2016-10-10T17:53:29Z","isPatch":false,"sender":{"key":"paul@mad-scientist.net","avatar":"https://avatars.githubusercontent.com/u/109636?v=4"},"body":"On Mon, 2016-10-10 at 10:19 +0000, Eduard Egorov wrote:\n> # ~/gitbuild/git-2.10.1/git merge -s subtree --squash ceph_ansible\n> \n> Can somebody confirm this please? Doesn't \"merge -s subtree\" really\n> merges branches?\n\nI think possibly you're not fully understanding what the --squash flag\ndoes... that's what's causing your issue here, not the \"-s\" option.\n\nA squash merge takes the commits that would be merged from the origin\nbranch and squashes them into a single patch and applies them to the\ncurrent branch as a new commit... but this new commit is not a merge\ncommit (that is, when you look at it with \"git show\" etc. the commit\nwill have only one parent, not two--or more--parents like a normal merge\ncommit).\n\nBasically, it's syntactic sugar for a diff plus patch operation plus\nsome Git goodness wrapped around it to make it easier to use.\n\nBut ultimately once you're done, Git has no idea that this new commit\nhas any relationship whatsoever to the origin branch.  So the next time\nyou merge, Git doesn't know that there was a previous merge and it will\ntry to merge everything from scratch rather than starting at the\nprevious common merge point.\n\nSo either you'll have to use a normal, non-squash merge, or else you'll\nhave to tell Git by hand what the previous common merge point was (as\nJeff King's excellent email suggests).  Or else, you'll have to live\nwith this behavior.\n"},{"id":"303877","messageId":"94ff5fb3-6957-8983-4aa7-e1d5e2692e82@gmail.com","threadId":"44270","inReplyTo":"1476121942.15746.99.camel@mad-scientist.net","subject":"Re: git merge deletes my changes","fromName":"Jakub Narębski","fromEmail":"jnareb@gmail.com","sentAt":"2016-10-11T15:56:48Z","receivedAt":"2016-10-11T15:57:03Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"W dniu 10.10.2016 o 19:52, Paul Smith pisze:\n> On Mon, 2016-10-10 at 10:19 +0000, Eduard Egorov wrote:\n>> # ~/gitbuild/git-2.10.1/git merge -s subtree --squash ceph_ansible\n>>\n>> Can somebody confirm this please? Doesn't \"merge -s subtree\" really\n>> merges branches?\n> \n> I think possibly you're not fully understanding what the --squash flag\n> does... that's what's causing your issue here, not the \"-s\" option.\n> \n> A squash merge takes the commits that would be merged from the origin\n> branch and squashes them into a single patch and applies them to the\n> current branch as a new commit... but this new commit is not a merge\n> commit (that is, when you look at it with \"git show\" etc. the commit\n> will have only one parent, not two--or more--parents like a normal merge\n> commit).\n> \n> Basically, it's syntactic sugar for a diff plus patch operation plus\n> some Git goodness wrapped around it to make it easier to use.\n\nActually this is full merge + commit surgery (as if you did merge with\n--no-commit, then deleted MERGE_HEAD); the state of worktree is as if\nit were after a merge.\n\n> \n> But ultimately once you're done, Git has no idea that this new commit\n> has any relationship whatsoever to the origin branch.  So the next time\n> you merge, Git doesn't know that there was a previous merge and it will\n> try to merge everything from scratch rather than starting at the\n> previous common merge point.\n> \n> So either you'll have to use a normal, non-squash merge, or else you'll\n> have to tell Git by hand what the previous common merge point was (as\n> Jeff King's excellent email suggests).  Or else, you'll have to live\n> with this behavior.\n\nThe `git subtree` command (from contrib) allows yet another way: it\nsquashes *history* of merged subproject (as if with interactive rebase\n'squash'), then merges this squash commit.\n\nNow I know why this feature is here...\n-- \nJakub Narębski\n\n"},{"id":"303970","messageId":"AM4PR03MB1636DC3017FFA1DE57BAABADDBDD0@AM4PR03MB1636.eurprd03.prod.outlook.com","threadId":"44270","inReplyTo":"94ff5fb3-6957-8983-4aa7-e1d5e2692e82@gmail.com","subject":"RE: git merge deletes my changes","fromName":"Eduard Egorov","fromEmail":"eduard.egorov@icl-services.com","sentAt":"2016-10-12T05:51:58Z","receivedAt":"2016-10-12T09:27:46Z","isPatch":false,"sender":{"key":"eduard.egorov@icl-services.com","avatar":null},"body":"Hello Jakub,\n\nThank you for addition. Eventually, I've merged your explanations into single answer post (http://stackoverflow.com/questions/39954265/git-merge-s-subtree-works-incorrectly/ ). I hope this will prevent other confused people from disturbing you by similar emails on this mailing list.\n\nThis is another time I can evidence the power and flexibility the git provides, thank you all for your great work!\n\nWith best regards\nEduard Egorov\n\n-----Original Message-----\nFrom: Jakub Narębski [mailto:jnareb@gmail.com] \nSent: Tuesday, October 11, 2016 6:57 PM\nTo: Paul Smith; Eduard Egorov; 'git@vger.kernel.org'\nSubject: Re: git merge deletes my changes\n\nW dniu 10.10.2016 o 19:52, Paul Smith pisze:\n> On Mon, 2016-10-10 at 10:19 +0000, Eduard Egorov wrote:\n>> # ~/gitbuild/git-2.10.1/git merge -s subtree --squash ceph_ansible\n>>\n>> Can somebody confirm this please? Doesn't \"merge -s subtree\" really \n>> merges branches?\n> \n> I think possibly you're not fully understanding what the --squash flag \n> does... that's what's causing your issue here, not the \"-s\" option.\n> \n> A squash merge takes the commits that would be merged from the origin \n> branch and squashes them into a single patch and applies them to the \n> current branch as a new commit... but this new commit is not a merge \n> commit (that is, when you look at it with \"git show\" etc. the commit \n> will have only one parent, not two--or more--parents like a normal \n> merge commit).\n> \n> Basically, it's syntactic sugar for a diff plus patch operation plus \n> some Git goodness wrapped around it to make it easier to use.\n\nActually this is full merge + commit surgery (as if you did merge with --no-commit, then deleted MERGE_HEAD); the state of worktree is as if it were after a merge.\n\n> \n> But ultimately once you're done, Git has no idea that this new commit \n> has any relationship whatsoever to the origin branch.  So the next \n> time you merge, Git doesn't know that there was a previous merge and \n> it will try to merge everything from scratch rather than starting at \n> the previous common merge point.\n> \n> So either you'll have to use a normal, non-squash merge, or else \n> you'll have to tell Git by hand what the previous common merge point \n> was (as Jeff King's excellent email suggests).  Or else, you'll have \n> to live with this behavior.\n\nThe `git subtree` command (from contrib) allows yet another way: it squashes *history* of merged subproject (as if with interactive rebase 'squash'), then merges this squash commit.\n\nNow I know why this feature is here...\n--\nJakub Narębski\n\n"}]}