{"thread":{"id":"53236","subject":"Move some files, with all history, from one project into a new one","startedAt":"2020-04-15T08:33:07Z","lastAt":"2020-04-17T13:49:14Z","messageCount":5,"participants":["Kerry, Richard","Jeff King","Taylor Blau","Elijah Newren"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"395479","messageId":"AM0PR02MB3715F9566BD9FEFAF832F0749CDB0@AM0PR02MB3715.eurprd02.prod.outlook.com","threadId":"53236","inReplyTo":null,"subject":"Move some files, with all history, from one project into a new one","fromName":"Kerry, Richard","fromEmail":"richard.kerry@atos.net","sentAt":"2020-04-15T08:31:35Z","receivedAt":"2020-04-15T08:33:07Z","isPatch":false,"sender":{"key":"richard.kerry@atos.net","avatar":null},"body":"I would like to move some files, from the project in which they have always resided into  a new project.  I would like to keep all their history.\nI don't want to waste space by also moving the rest of the old project's history, or historical file contents.\n\nWe have a long-standing project, main-system.  A group of files within it are designated as demo-system (sometimes whole folders, sometimes files within folders with other files).\nAll development is done on the master branch.\nIt has now transpired that the demo-system files are necessary, but no longer want to be within main-system but in a new project of their own.  So I would like to move them from the main-system repo into a new repo of their own.  I do want all their history but I don't want to take any contents from other files from main-system, which is quite big.\nPlease can someone advise if there is a particular method I should best use for this.\nDo I create a new branch, then delete the rest of main-system leaving only what I want?  Surely if I do that then I would end up with all the main-system file data within the new repo, which would expand its size.\nIs there a recommended way to extract certain files with their histories?\n\nRegards,\nRichard.\n\n"},{"id":"395500","messageId":"20200415151128.GA2464307@coredump.intra.peff.net","threadId":"53236","inReplyTo":"AM0PR02MB3715F9566BD9FEFAF832F0749CDB0@AM0PR02MB3715.eurprd02.prod.outlook.com","subject":"Re: Move some files, with all history, from one project into a new one","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-04-15T15:11:28Z","receivedAt":"2020-04-15T15:11:39Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Apr 15, 2020 at 08:31:35AM +0000, Kerry, Richard wrote:\n\n> I would like to move some files, from the project in which they have\n> always resided into  a new project.  I would like to keep all their\n> history.  I don't want to waste space by also moving the rest of the\n> old project's history, or historical file contents.\n\nTry git-filter-branch's --subdirectory repository, which is designed to\ndo exactly this.\n\nOr the much newer (and faster) git-filter-repo:\n\n  https://github.com/newren/git-filter-repo\n\n> Do I create a new branch, then delete the rest of main-system leaving\n> only what I want?  Surely if I do that then I would end up with all\n> the main-system file data within the new repo, which would expand its\n> size.  Is there a recommended way to extract certain files with their\n> histories?\n\nCorrect; just deleting files and creating a new commit will still carry\nthem in the history. You have to rewrite the old commits.\n\n-Peff\n"},{"id":"395508","messageId":"20200415154944.GA22823@syl.local","threadId":"53236","inReplyTo":"20200415151128.GA2464307@coredump.intra.peff.net","subject":"Re: Move some files, with all history, from one project into a new one","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2020-04-15T15:49:44Z","receivedAt":"2020-04-15T15:49:59Z","isPatch":false,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, Apr 15, 2020 at 11:11:28AM -0400, Jeff King wrote:\n> On Wed, Apr 15, 2020 at 08:31:35AM +0000, Kerry, Richard wrote:\n>\n> > I would like to move some files, from the project in which they have\n> > always resided into  a new project.  I would like to keep all their\n> > history.  I don't want to waste space by also moving the rest of the\n> > old project's history, or historical file contents.\n>\n> Try git-filter-branch's --subdirectory repository, which is designed to\n> do exactly this.\n>\n> Or the much newer (and faster) git-filter-repo:\n>\n>   https://github.com/newren/git-filter-repo\n\nFor what it's worth, Elijah has provided some excellent documentation on\nhow to use git-filter-repo to do exactly this here:\n\n  https://github.com/newren/git-filter-repo#solving-this-with-filter-repo\n\nThanks,\nTaylor\n"},{"id":"395574","messageId":"CABPp-BF7o1ba4=qqkqYjMm=YzuH5A=YU+C5zbd41g4pNY4yRKQ@mail.gmail.com","threadId":"53236","inReplyTo":"20200415154944.GA22823@syl.local","subject":"Re: Move some files, with all history, from one project into a new one","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2020-04-16T06:05:53Z","receivedAt":"2020-04-16T06:06:21Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Wed, Apr 15, 2020 at 8:49 AM Taylor Blau <me@ttaylorr.com> wrote:\n>\n> On Wed, Apr 15, 2020 at 11:11:28AM -0400, Jeff King wrote:\n> > On Wed, Apr 15, 2020 at 08:31:35AM +0000, Kerry, Richard wrote:\n> >\n> > > I would like to move some files, from the project in which they have\n> > > always resided into  a new project.  I would like to keep all their\n> > > history.  I don't want to waste space by also moving the rest of the\n> > > old project's history, or historical file contents.\n> >\n> > Try git-filter-branch's --subdirectory repository, which is designed to\n> > do exactly this.\n> >\n> > Or the much newer (and faster) git-filter-repo:\n> >\n> >   https://github.com/newren/git-filter-repo\n>\n> For what it's worth, Elijah has provided some excellent documentation on\n> how to use git-filter-repo to do exactly this here:\n>\n>   https://github.com/newren/git-filter-repo#solving-this-with-filter-repo\n\nThat particular example might be for a different case than what\nRichard requested, though.  Let's say the original repo had a file\nstructure like the following:\n\n   module/\n      foo.c\n      bar.c\n   otherDir/\n      blah.config\n      stuff.txt\n   zebra.jpg\n\nIf the request is to e.g. take module/ and all files within it with\ntheir history and make a new repository out of it, with module/ being\nremapped to the root of the repository, then you would want:\n   git filtrer-repo --subdirectory-filter module\nand yes, this looks exactly like filter-branch; that's the one flag I\ncopied from it.  So this one usecase maps directly between the two\ntools.\n\nIn contrast, if you wanted to keep all files from the original repo\nbut move everything into a subdirectory named \"myProject\" (so that\ne.g. module/foo.c became myProject/module/foo.c), possibly in\npreparation for merging your repo into some larger monorepo, then\nyou'd want to pass `--to-subdirectory-filter myProject` as in the link\nyou pointed out.  filter-branch doesn't have an equivalent.\n\n\nHope that helps,\nElijah\n"},{"id":"395659","messageId":"AM0PR02MB37156EF466D56AAD182666609CD90@AM0PR02MB3715.eurprd02.prod.outlook.com","threadId":"53236","inReplyTo":"CABPp-BF7o1ba4=qqkqYjMm=YzuH5A=YU+C5zbd41g4pNY4yRKQ@mail.gmail.com","subject":"RE: Move some files, with all history, from one project into a new one","fromName":"Kerry, Richard","fromEmail":"richard.kerry@atos.net","sentAt":"2020-04-17T13:48:58Z","receivedAt":"2020-04-17T13:49:14Z","isPatch":false,"sender":{"key":"richard.kerry@atos.net","avatar":null},"body":"\nThanks All.\nI've cloned git-filter-repo and I shall shortly give it a try.\n\nFirst step is to get Python 3 installed (I'm on Windows).\n\nRegards,\nRichard.\n\n\n\n-----Original Message-----\nFrom: Elijah Newren <newren@gmail.com> \nSent: 16 April 2020 07:06\nTo: Taylor Blau <me@ttaylorr.com>\nCc: Jeff King <peff@peff.net>; Kerry, Richard <richard.kerry@atos.net>; git@vger.kernel.org\nSubject: Re: Move some files, with all history, from one project into a new one\n\nCaution! External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.\n\nOn Wed, Apr 15, 2020 at 8:49 AM Taylor Blau <me@ttaylorr.com> wrote:\n>\n> On Wed, Apr 15, 2020 at 11:11:28AM -0400, Jeff King wrote:\n> > On Wed, Apr 15, 2020 at 08:31:35AM +0000, Kerry, Richard wrote:\n> >\n> > > I would like to move some files, from the project in which they \n> > > have always resided into  a new project.  I would like to keep all \n> > > their history.  I don't want to waste space by also moving the \n> > > rest of the old project's history, or historical file contents.\n> >\n> > Try git-filter-branch's --subdirectory repository, which is designed \n> > to do exactly this.\n> >\n> > Or the much newer (and faster) git-filter-repo:\n> >\n> >   \n> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgi\n> > thub.com%2Fnewren%2Fgit-filter-repo&amp;data=02%7C01%7Crichard.kerry\n> > %40atos.net%7Cf28b944624e04084395f08d7e1cc7b35%7C33440fc6b7c7412cbb7\n> > 30e70b0198d5a%7C0%7C0%7C637226140664962267&amp;sdata=pb2EnEADuC9Bdi5\n> > JU2So3DK6VyEcsEH5X5kybFAw9%2FM%3D&amp;reserved=0\n>\n> For what it's worth, Elijah has provided some excellent documentation \n> on how to use git-filter-repo to do exactly this here:\n>\n>   \n> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgith\n> ub.com%2Fnewren%2Fgit-filter-repo%23solving-this-with-filter-repo&amp;\n> data=02%7C01%7Crichard.kerry%40atos.net%7Cf28b944624e04084395f08d7e1cc\n> 7b35%7C33440fc6b7c7412cbb730e70b0198d5a%7C0%7C0%7C637226140664962267&a\n> mp;sdata=h03FogXX0iuqHB9d49CltOmzNkwGK66chC5ZvhOyWfs%3D&amp;reserved=0\n\nThat particular example might be for a different case than what Richard requested, though.  Let's say the original repo had a file structure like the following:\n\n   module/\n      foo.c\n      bar.c\n   otherDir/\n      blah.config\n      stuff.txt\n   zebra.jpg\n\nIf the request is to e.g. take module/ and all files within it with their history and make a new repository out of it, with module/ being remapped to the root of the repository, then you would want:\n   git filtrer-repo --subdirectory-filter module and yes, this looks exactly like filter-branch; that's the one flag I copied from it.  So this one usecase maps directly between the two tools.\n\nIn contrast, if you wanted to keep all files from the original repo but move everything into a subdirectory named \"myProject\" (so that e.g. module/foo.c became myProject/module/foo.c), possibly in preparation for merging your repo into some larger monorepo, then you'd want to pass `--to-subdirectory-filter myProject` as in the link you pointed out.  filter-branch doesn't have an equivalent.\n\n\nHope that helps,\nElijah\n"}]}