{"thread":{"id":"3700","subject":"Best way to generate a git tree containing only a subset of commits from another tree?","startedAt":"2006-03-22T19:28:52Z","lastAt":"2006-03-23T03:43:25Z","messageCount":7,"participants":["Anton Altaparmakov","Radoslaw Szkodzinski","Petr Baudis","Andreas Ericsson","Junio C Hamano","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"17777","messageId":"Pine.LNX.4.64.0603221920260.22475@hermes-2.csi.cam.ac.uk","threadId":"3700","inReplyTo":null,"subject":"Best way to generate a git tree containing only a subset of commits from another tree?","fromName":"Anton Altaparmakov","fromEmail":"aia21@cam.ac.uk","sentAt":"2006-03-22T19:28:52Z","receivedAt":"2006-03-22T19:28:52Z","isPatch":false,"sender":{"key":"aia21@cam.ac.uk","avatar":null},"body":"As subject, what is at present the best way to generate a git tree \ncontaining only a subset of commits from another tree.\n\nSo I have /usr/src/my-big-tree and /usr/src/linux-2.6 and now I want to \nadd some of the commits in my-big-tree to the tree linux-2.6 so I can push \nout to Linus.\n\nPreferable I would like to do it so that later when Linus has pulled from \nmy /usr/src/linux-2.6 tree, I do a \"git pull\" of Linus' tree from \n/usr/src/my-big-tree and it all works correctly and I don't end up with \nthe same commits twice.\n\nIs that possible at all?\n\nIf not what can I do to do it cleanly?  Does git help in any way or do I \nliterally have to export all my commits from /usr/src/my-big-tree to diff \nstyle patches and then throw away the tree, clone Linus tree after he has \npulled my /usr/src/linux-2.6 tree and commit all my generated diff patches \nagain?  That would be rather horrible to have to do...\n\nI am happy to be pointed to a FAQ or RTFM if you tell me where to look for \nit...\n\nThanks a lot in advance!\n\nPS. Please keep me CC:-ed as I am not on the git mailing list any more.\n\nBest regards,\n\n\tAnton\n-- \nAnton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)\nUnix Support, Computing Service, University of Cambridge, CB2 3QH, UK\nLinux NTFS maintainer / IRC: #ntfs on irc.freenode.net\nWWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/\n"},{"id":"17784","messageId":"200603222229.02763.astralstorm@o2.pl","threadId":"3700","inReplyTo":"Pine.LNX.4.64.0603221920260.22475@hermes-2.csi.cam.ac.uk","subject":"Re: Best way to generate a git tree containing only a subset of commits from another tree?","fromName":"Radoslaw Szkodzinski","fromEmail":"astralstorm@o2.pl","sentAt":"2006-03-22T21:28:57Z","receivedAt":"2006-03-22T21:28:57Z","isPatch":false,"sender":{"key":"astralstorm@o2.pl","avatar":null},"body":"On Wednesday 22 March 2006 20:28, Anton Altaparmakov wrote yet:\n> Preferable I would like to do it so that later when Linus has pulled from\n> my /usr/src/linux-2.6 tree, I do a \"git pull\" of Linus' tree from\n> /usr/src/my-big-tree and it all works correctly and I don't end up with\n> the same commits twice.\n>\n> Is that possible at all?\n\nShould work out of the box.\n\n> If not what can I do to do it cleanly?  Does git help in any way or do I\n> literally have to export all my commits from /usr/src/my-big-tree to diff\n> style patches and then throw away the tree, clone Linus tree after he has\n> pulled my /usr/src/linux-2.6 tree and commit all my generated diff patches\n> again?  That would be rather horrible to have to do...\n\nIt will work flawlessly if Linus merges your patch without any changes.\nElse git will merge and maybe conflict if the change was major.\n\n-- \nGPG Key id:  0xD1F10BA2\nFingerprint: 96E2 304A B9C4 949A 10A0  9105 9543 0453 D1F1 0BA2\n\nAstralStorm\n"},{"id":"17790","messageId":"20060323002543.GU18185@pasky.or.cz","threadId":"3700","inReplyTo":"Pine.LNX.4.64.0603221920260.22475@hermes-2.csi.cam.ac.uk","subject":"Re: Best way to generate a git tree containing only a subset of commits from another tree?","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-03-23T00:25:43Z","receivedAt":"2006-03-23T00:25:43Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Wed, Mar 22, 2006 at 08:28:52PM CET, I got a letter\nwhere Anton Altaparmakov <aia21@cam.ac.uk> said that...\n> Preferable I would like to do it so that later when Linus has pulled from \n> my /usr/src/linux-2.6 tree, I do a \"git pull\" of Linus' tree from \n> /usr/src/my-big-tree and it all works correctly and I don't end up with \n> the same commits twice.\n> \n> Is that possible at all?\n\nNot with Git - you will end up with the same commits twice, once when\nyou originally committed them and once coming cherry-picked from your\nlinux-2.6 tree through Linus' tree.\n\n> If not what can I do to do it cleanly?  Does git help in any way or do I \n> literally have to export all my commits from /usr/src/my-big-tree to diff \n> style patches and then throw away the tree, clone Linus tree after he has \n> pulled my /usr/src/linux-2.6 tree and commit all my generated diff patches \n> again?  That would be rather horrible to have to do...\n\nYes, that's the way to go, but actually it's not horrible at all because\nthere's a tool to help you - check out StGIT, which will let you\nmaintain a stack of patches on top of a git tree and do all sorts of\ncool stuff with them (including rebasing them to new tree revision, the\nmost important thing for you).\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nRight now I am having amnesia and deja-vu at the same time.  I think\nI have forgotten this before.\n"},{"id":"17791","messageId":"4421EF5F.3000601@op5.se","threadId":"3700","inReplyTo":"Pine.LNX.4.64.0603221920260.22475@hermes-2.csi.cam.ac.uk","subject":"Re: Best way to generate a git tree containing only a subset of commits from another tree?","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2006-03-23T00:44:15Z","receivedAt":"2006-03-23T00:44:15Z","isPatch":false,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Anton Altaparmakov wrote:\n> As subject, what is at present the best way to generate a git tree \n> containing only a subset of commits from another tree.\n> \n\ngit format-patch -k <start-commit>..<end-commit> --stdout | git am -k\n\nMake sure you're on the right branch first, but see below.\n\n> So I have /usr/src/my-big-tree and /usr/src/linux-2.6 and now I want to \n> add some of the commits in my-big-tree to the tree linux-2.6 so I can push \n> out to Linus.\n> \n\nI sense some nomenclature confusion here. By \"tree\", do you happen to \nmean \"branch\", or possibly \"repository\"? I know bk does things with \ntrees that's vaguely git-ish, but a tree in git is, basically, just a \nsimplified directory listing (without depth, although it can contain \nother trees ad infinitum iiuc).\n\nIf you mean \"branch\" (or repository, it doesn't matter since by then \nyou'll have something like a master branch anyway), as I think you do, \nthen let's assume the Vanilla Linux lives in the \"linus\" branch.\n\nYou would then do\n\n    $ git checkout -b for-linus linus\n\nfollowed by either multiple\n    $ git cherry-pick <commit-ish>\n\nor, if the commits are all in series, an iteration of the following\n\n    $ git format-patch --stdout <start-commit>..<end-commit> | git am -k\n\nIf you have several topic branches, one for each series of commits, you \nshould be able to do an octopus, like so:\n    $ git pull . <topic-branches-to-publish>\n\nIf you *don't* have several topic branches, or if some commits aren't in \ntopic-branches, you could try something like this (untested, although it \nshouldn't break anything except the for-linus branch which you can \nre-create fairly simply)\n\n   $ for b in <topic-branches-for-linus>; do\n       git checkout $b\n       git rebase for-linus || (git reset --hard; echo $b >> to-merge)\n     done\n   # now merge what couldn't be rebased\n   $ git checkout for-linus\n   $ git pull . $(cat to-merge)\n\nIn your \"please-pull\" mail to Linus, ask him to pull the 'for-linus' \nbranch. When he's done so, pull his 'master' branch to your 'linus', \nbranch and remove the 'for-linus' branch and re-create it from Linus' \nmaster branch again. If your vanilla tree is up-to-date and he pulls \nfrom you before pulling from someone else or adding other commits this \nisn't necessary, although you'll have to do\n    $ git checkout linus; git pull . for-linus\n\nto get the vanilla branch up to speed with Linus' HEAD.\n\n\nThat turned out a bit longer than I expected, and with me being slightly \noff sobriety at the moment it would be good if someone less so could \ndouble-check the thinking. Incidentally, this is one of the reasons why \ntopic-branches is such a Good Thing (tm).\n\n\n> Preferable I would like to do it so that later when Linus has pulled from \n> my /usr/src/linux-2.6 tree, I do a \"git pull\" of Linus' tree from \n> /usr/src/my-big-tree and it all works correctly and I don't end up with \n> the same commits twice.\n> \n> Is that possible at all?\n> \n\nI hope so, or I just spent a good 20 minutes not drinking beer for \nnothing. ;)\n\n\n> If not what can I do to do it cleanly?  Does git help in any way or do I \n> literally have to export all my commits from /usr/src/my-big-tree to diff \n> style patches and then throw away the tree, clone Linus tree after he has \n> pulled my /usr/src/linux-2.6 tree and commit all my generated diff patches \n> again?  That would be rather horrible to have to do...\n> \n\nIt's worth re-iterating:\ngit format-patch --stdout -k <start-commit>..<end-commit> > patch-series\ngit am -k patch-series\n\nIt will save you a lot of work.\n\n> I am happy to be pointed to a FAQ or RTFM if you tell me where to look for \n> it...\n> \n\nHopefully I just supplied one that can be re-used with some \ntext-mangling by someone capable of being legible and making sense at \nthe same time.\n\nFor more info, check out the man-pages of the commands above (notably \nthe cherry-pick man-page and the pull command's \"merge with local\" feature).\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"},{"id":"17796","messageId":"7vu09q54a6.fsf@assigned-by-dhcp.cox.net","threadId":"3700","inReplyTo":"4421EF5F.3000601@op5.se","subject":"Re: Best way to generate a git tree containing only a subset of commits from another tree?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-03-23T01:38:25Z","receivedAt":"2006-03-23T01:38:25Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andreas Ericsson <ae@op5.se> writes:\n\n> You would then do\n>\n>    $ git checkout -b for-linus linus\n>\n> followed by either multiple\n>\n>    $ git cherry-pick <commit-ish>\n>\n> or, if the commits are all in series, an iteration of the following\n>\n>    $ git format-patch --stdout <start-commit>..<end-commit> | git am -k\n\nWith core git tools these two would be the idiom to use.  It\nmight be more pleasant to use a specialized tool (such as StGIT)\ndesigned to manage the changes meant for upstream.\n\n> If you have several topic branches, one for each series of commits,\n> you should be able to do an octopus, like so:\n>\n>    $ git pull . <topic-branches-to-publish>\n\nOctopus is orthogonal to the issue at hand.  Further, I suspect\nthat the original repository by Anton is not that cleanly\norganized to have such topic branches -- otherwise the question\nwould not have come up to begin with.\n\n> If you *don't* have several topic branches, or if some commits aren't\n> in topic-branches, you could try something like this (untested,\n> although it shouldn't break anything except the for-linus branch which\n> you can re-create fairly simply)\n>\n>   $ for b in <topic-branches-for-linus>; do\n>       git checkout $b\n>       git rebase for-linus || (git reset --hard; echo $b >> to-merge)\n>     done\n\n>   # now merge what couldn't be rebased\n>   $ git checkout for-linus\n>   $ git pull . $(cat to-merge)\n\nNow you lost me here.  When rebase refuses because of\nconflicting changes, you are doing \"reset --hard\" but I suspect\nyou meant \"reset --hard ORIG_HEAD\" to recover the original head.\nFurther, I would have expected you to be rebasing on top of\nlinus, not for-linus, in case you may already have pulled other\ntopic branches into it.\n\nYour merging those branches that have conflicting changes on top\nof for-linus (that starts out at Linus's tip) is sensible, but\none word of caution is the history contained within the topic\nbranch should be sane.  What are you going to do with branches\nthat cleanly rebase on top of for-linus?\n\n> ... If your vanilla tree is up-to-date and he pulls\n> from you before pulling from someone else or adding other commits this\n> isn't necessary, although you'll have to do\n>\n>    $ git checkout linus; git pull . for-linus\n>\n> to get the vanilla branch up to speed with Linus' HEAD.\n\nI am not sure I follow you here.\n\nIf Linus hasn't pulled from you, you can either just keep asking\n(you do not have to update for-linus), or rebuild it based on\nmore recent Linus's tip.\n\n\t$ git fetch linus ;# to update to Linus's tip\n\t$ git checkout for-linus\n        $ git reset --hard linus\n\nIf Linus has pulled from you, there is nothing more than the\nabove for you to do.  If you want to rebuild for-linus branch,\n(maybe because you fixed things in some of your topic branches),\nafter the above, you could:\n\n        $ git pull . this-topic\n        $ git pull . that-topic\n        ...\n\nThis is nicer to Linus _if_ your topics overlap with recent\nchanges to the Linus's tree.  Otherwise you do not necessarily\nhave to rebuild for-linus branch.\n"},{"id":"17803","messageId":"442213F4.7040603@op5.se","threadId":"3700","inReplyTo":"7vu09q54a6.fsf@assigned-by-dhcp.cox.net","subject":"Re: Best way to generate a git tree containing only a subset of commits from another tree?","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2006-03-23T03:20:20Z","receivedAt":"2006-03-23T03:20:20Z","isPatch":false,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Junio C Hamano wrote:\n> Andreas Ericsson <ae@op5.se> writes:\n> \n  >>If you have several topic branches, one for each series of commits,\n>>you should be able to do an octopus, like so:\n>>\n>>   $ git pull . <topic-branches-to-publish>\n> \n> \n> Octopus is orthogonal to the issue at hand.  Further, I suspect\n> that the original repository by Anton is not that cleanly\n> organized to have such topic branches -- otherwise the question\n> would not have come up to begin with.\n> \n\n<sidenote>\nI've never understood what orthogonal means in this sense. \"at a right \nangle\" as in flagging for attention or the exactly counter-productive to \nwhat one should use?\n</sidenot>\n\n> \n>>If you *don't* have several topic branches, or if some commits aren't\n>>in topic-branches, you could try something like this (untested,\n>>although it shouldn't break anything except the for-linus branch which\n>>you can re-create fairly simply)\n>>\n>>  $ for b in <topic-branches-for-linus>; do\n>>      git checkout $b\n>>      git rebase for-linus || (git reset --hard; echo $b >> to-merge)\n>>    done\n> \n> \n>>  # now merge what couldn't be rebased\n>>  $ git checkout for-linus\n>>  $ git pull . $(cat to-merge)\n> \n> \n> Now you lost me here.  When rebase refuses because of\n> conflicting changes, you are doing \"reset --hard\" but I suspect\n> you meant \"reset --hard ORIG_HEAD\" to recover the original head.\n\n\nI actually meant to reset the for-linus branch, although it would have \nto be reset to the state it was before trying the rebase, which means \ncreating and deleting a tag or some other marker.\n\nI really should install an alco-lock on my MUA.\n\n\n> Further, I would have expected you to be rebasing on top of\n> linus, not for-linus, in case you may already have pulled other\n> topic branches into it.\n> \n\nPerhaps. I said 'for-linus' to make sure there was an easy way to \nrecover to state 1 in case of errors. I also rewrote the part above \ntwice to account for topic branches, so it doesn't make much sense \nwithout the background thinking.\n\n\n> Your merging those branches that have conflicting changes on top\n> of for-linus (that starts out at Linus's tip) is sensible, but\n> one word of caution is the history contained within the topic\n> branch should be sane.  What are you going to do with branches\n> that cleanly rebase on top of for-linus?\n> \n\nNothing. 'for-linus' should be updated each time a rebase completes \nsuccess-fully, so all the cleanly rebased branches should be in a linear \ncommit-history on top of each other. Granted, most projects won't have \nmany topic-branches (or other commit-chains) that rebase on top of each \nother like that, but...\n\n> \n>>... If your vanilla tree is up-to-date and he pulls\n>>from you before pulling from someone else or adding other commits this\n>>isn't necessary, although you'll have to do\n>>\n>>   $ git checkout linus; git pull . for-linus\n>>\n>>to get the vanilla branch up to speed with Linus' HEAD.\n> \n> \n> I am not sure I follow you here.\n> \n> If Linus hasn't pulled from you, you can either just keep asking\n> (you do not have to update for-linus), or rebuild it based on\n> more recent Linus's tip.\n> \n\nWhat I meant was that the thing he has in \"for-linus\" will match what \nLinus has in \"master\" verbatim if Linus doesn't have commits on top of \nhis \"master\" that aren't in Anton's \"for-linus\" (originating from \n\"linus\"). That sentence didn't make sense to me right now.\n\n> \t$ git fetch linus ;# to update to Linus's tip\n> \t$ git checkout for-linus\n>         $ git reset --hard linus\n> \n> If Linus has pulled from you, there is nothing more than the\n> above for you to do.\n\nThe above command would reset the \"for-linus\" branch to the state it had \nbefore he applied all his changes. I meant that if he wants to track \nLinus' exact HEAD in some branch he could do that by tracking his own if \nthe changes since merge-base are identical. I was clearly complicating \nthings by mentioning such a highly conditional exception.\n\n\n>  If you want to rebuild for-linus branch,\n> (maybe because you fixed things in some of your topic branches),\n> after the above, you could:\n> \n>         $ git pull . this-topic\n>         $ git pull . that-topic\n>         ...\n> \n> This is nicer to Linus _if_ your topics overlap with recent\n> changes to the Linus's tree.  Otherwise you do not necessarily\n> have to rebuild for-linus branch.\n> \n\nBut it's very nasty in case Linus has already pulled the changes, which \nwas what I assumed he would have done.\n\nI was most likely a bit diffuse. Everything else seems to be at the \nmoment, and I like to blend in. ;)\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"},{"id":"17804","messageId":"Pine.LNX.4.64.0603221932040.26286@g5.osdl.org","threadId":"3700","inReplyTo":"442213F4.7040603@op5.se","subject":"Re: Best way to generate a git tree containing only a subset of commits from another tree?","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-03-23T03:43:25Z","receivedAt":"2006-03-23T03:43:25Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 23 Mar 2006, Andreas Ericsson wrote:\n> \n> <sidenote>\n> I've never understood what orthogonal means in this sense. \"at a right angle\"\n> as in flagging for attention or the exactly counter-productive to what one\n> should use?\n> </sidenot>\n\nNo. Orthogonal in math may be literally \"straight angle\", but in \nnon-geometric speak it means \"independent\" or \"statistically unrelated\".\n\nSee \n\n\thttp://wordnet.princeton.edu/perl/webwn?s=orthogonal\n\nand the two first definitions in particular.\n\nIe two issues (or, in this case, \"branches\") are orthogonal if they have \nnothing in common - they fix two totally independent things.\n\nThis is, btw, totally consistent with the geometric meaning of the word. \nTwo vectors are orthogonal if they have no common component: the dot \nproduct is zero (ie the projection of one vector onto another is the null \nvector).\n\nSo if you see two lines of development as being \"vectors\" from a common \nsource, when they have nothing in common, they are orthogonal.\n\nOf course, the development space is neither three-dimensional nor \neuclidian, so it's a strange kind of vector, but still ;)\n\n\t\tLinus\n"}]}