{"thread":{"id":"14635","subject":"git merge after git cherry-pick?","startedAt":"2008-07-23T17:14:49Z","lastAt":"2008-07-23T19:35:58Z","messageCount":4,"participants":["Peter Valdemar Mørch (Lists)","SZEDER Gábor","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"84553","messageId":"48876709.3090504@sneakemail.com","threadId":"14635","inReplyTo":null,"subject":"git merge after git cherry-pick?","fromName":"Peter Valdemar Mørch (Lists)","fromEmail":"4ux6as402@sneakemail.com","sentAt":"2008-07-23T17:14:49Z","receivedAt":"2008-07-23T17:14:49Z","isPatch":false,"sender":{"key":"4ux6as402@sneakemail.com","avatar":null},"body":"Hi,\n\nStill being a newbie...\n\nOn a branch, b, made off of master, I've made the commits b1, b2, b3 and \nb4.\n\nBack on master, I need commit b1 and b3 immediately. So I:\n\n$ git checkout master\n$ git cherry-pick \"b1's SHA\"\n$ git cherry-pick \"b3's SHA\"\n\nNow, both b and master contain b1 and b3. How do I now create a log of \n\"what remains to be merged from b to master\", i.e. only b2 and b4? And \nhow do I merge b2 and b4 to master, so master's log shows b1, b3, b2 and \nb4 and doesn't show b1 and b3 twice, which is what I get if I:\n\n$ git merge b\n\nafter the cherry-picks above. Also I noticed, that if I merge master \ninto b (to keep up-to-date with master) b1 and b3 are also mentioned twice.\n\nI did notice that cherry-pick created new SHA1 IDs for the commits for \nb1 and b3 on master (as indeed man cherry-pick also says). Maybe \ncherry-pick is not the right tool for the job. Is there another way to \n\"copy\"/\"merge\" only b1 and b3 (but not b2 and b4) from b into master \nmaintaining merge history and avoiding them being mentioned twice later?\n\nAt the time of writing b1-b4, I did not know that b1 and b3 would be \nneeded separately, so I didn't put (b1 and b3) and (b2 and b4) on \nseparate branches. I did notice though, that they weren't an intricate \npart of \"the new feature\". Is it required that I then do the work in \nseparate branches?\n\nI hope this is possible as I'm thrilled with git!\n\nPeter\n-- \nPeter Valdemar Mørch\nhttp://www.morch.com\n"},{"id":"84558","messageId":"20080723175600.GL22606@neumann","threadId":"14635","inReplyTo":"48876709.3090504@sneakemail.com","subject":"Re: git merge after git cherry-pick?","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2008-07-23T17:56:00Z","receivedAt":"2008-07-23T17:56:00Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Wed, Jul 23, 2008 at 07:14:49PM +0200, \"Peter Valdemar Mørch (Lists)\" wrote:\n> On a branch, b, made off of master, I've made the commits b1, b2, b3 and  \n> b4.\n>\n> Back on master, I need commit b1 and b3 immediately. So I:\n>\n> $ git checkout master\n> $ git cherry-pick \"b1's SHA\"\n> $ git cherry-pick \"b3's SHA\"\n>\n> Now, both b and master contain b1 and b3. How do I now create a log of  \n> \"what remains to be merged from b to master\", i.e. only b2 and b4? And  \n> how do I merge b2 and b4 to master, so master's log shows b1, b3, b2 and  \n> b4 and doesn't show b1 and b3 twice, which is what I get if I:\n>\n> $ git merge b\n>\n> after the cherry-picks above. Also I noticed, that if I merge master  \n> into b (to keep up-to-date with master) b1 and b3 are also mentioned \n> twice.\nYou could use 'git rebase' for that.\n\ne.g. now the history of your master and b branches look like this:\n\n  o---X---b1'---b3'---Y   master\n   \\\n    b1---b2---b3---b4   b\n\nThe command 'git rebase master b' will then turn this history into the\nfollowing:\n\n  o---X---b1'---b3'---Y   master\n                       \\\n                        b2---b4   b\n\nAfter this 'git merge b' will do what you would like it to do.\n\n\nRegards,\nGábor\n"},{"id":"84559","messageId":"m3y73sv60v.fsf@localhost.localdomain","threadId":"14635","inReplyTo":"48876709.3090504@sneakemail.com","subject":"Re: git merge after git cherry-pick?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-07-23T17:56:25Z","receivedAt":"2008-07-23T17:56:25Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"\"Peter Valdemar Mørch (Lists)\"    <4ux6as402@sneakemail.com> writes:\n\n> On a branch, b, made off of master, I've made the commits b1, b2, b3\n> and b4.\n> \n> Back on master, I need commit b1 and b3 immediately. So I:\n> \n> $ git checkout master\n> $ git cherry-pick \"b1's SHA\"\n> $ git cherry-pick \"b3's SHA\"\n> \n> Now, both b and master contain b1 and b3. How do I now create a log of\n> \"what remains to be merged from b to master\", i.e. only b2 and b4?\n\nYou can use \"git cherry master b\" command (or just \"git cherry master\"\nif you are on branch 'b') to check which commits (based on patch id)\non branch 'b are already present on branch 'master'.\n\nAlternatively you can use \"git log --left-right master...b\" to check\nwhich comits are on which branch, although I think it wouldn't mark\nduplicated commits.\n\n> And how do I merge b2 and b4 to master, so master's log shows b1,\n> b3, b2 and b4 and doesn't show b1 and b3 twice, which is what I get\n> if I:\n> \n> $ git merge b\n> \n> after the cherry-picks above. Also I noticed, that if I merge master\n> into b (to keep up-to-date with master) b1 and b3 are also mentioned\n> twice.\n\nYou can instead of merging branch 'b' into master rebase it on top of\nmaster.\n\nThis would create instead of the following history (for merge):\n\n   ---*---b1'---b3'--------------M         <-- master\n       \\                        /\n        \\-b1----b2----b3----b4-/           <-- b\n\nthe following\n\n   ---*---b1'---b3'---b1'---b4'            <-- master, b\n       .                        \n        ..b1....b2....b3....b4             <.. b@{1} (reflog)         \n\n[cut]\n\nHTH\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"84592","messageId":"4887881E.6070702@sneakemail.com","threadId":"14635","inReplyTo":"20080723175600.GL22606@neumann","subject":"Re: git merge after git cherry-pick?","fromName":"Peter Valdemar Mørch (Lists)","fromEmail":"4ux6as402@sneakemail.com","sentAt":"2008-07-23T19:35:58Z","receivedAt":"2008-07-23T19:35:58Z","isPatch":false,"sender":{"key":"4ux6as402@sneakemail.com","avatar":null},"body":"SZEDER Gábor szeder-at-ira.uka.de |Lists| wrote:\n> You could use 'git rebase' for that.\n\n*Exactly* what I was looking for. Now I know what rebase is for! Thanks.\n\nPeter\n-- \nPeter Valdemar Mørch\nhttp://www.morch.com\n"}]}