{"thread":{"id":"13800","subject":"move git repository out of a folder?","startedAt":"2008-06-04T20:03:57Z","lastAt":"2008-06-04T20:18:29Z","messageCount":5,"participants":["Sean Brown","Shawn O. Pearce","Avery Pennarun","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"78659","messageId":"1086fb5f0806041303v7856404dxb95b5a450ac30ae1@mail.gmail.com","threadId":"13800","inReplyTo":null,"subject":"move git repository out of a folder?","fromName":"Sean Brown","fromEmail":"seanmichaelbrown@gmail.com","sentAt":"2008-06-04T20:03:57Z","receivedAt":"2008-06-04T20:03:57Z","isPatch":false,"sender":{"key":"seanmichaelbrown@gmail.com","avatar":"https://gravatar.com/avatar/6ff2a76c5b8cc3ee811b5c75c65ee629bbbf9a16ac61d06d9b7d223c38838c4e?d=mp&s=160"},"body":"Let's say I've got this directory structure of source files:\n\n/folderA\n/folderA/sourcecode/\n/folderA/sourcecode/file1.txt\n/folderA/sourcecode/file2.txt\netc...\n\nWhen putting the project under git source control, I did this:\n\ncd /folderA\ngit init\n\nSo now when colleagues clone my repository, they get the source code\nin the \"sourcecode\" folder.  I'd like to just make the repository\nsimply give them the source files, not in a directory.  In other\nwords, as if I had originally been smart and done this:\n\ncd /folderA/sourcecode\ngit init\n\nCan I make that happen without losing all of the history?\n\nThanks,\n\nSean\n"},{"id":"78661","messageId":"20080604200724.GV12896@spearce.org","threadId":"13800","inReplyTo":"1086fb5f0806041303v7856404dxb95b5a450ac30ae1@mail.gmail.com","subject":"Re: move git repository out of a folder?","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-06-04T20:07:24Z","receivedAt":"2008-06-04T20:07:24Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Sean Brown <seanmichaelbrown@gmail.com> wrote:\n> Let's say I've got this directory structure of source files:\n> \n> /folderA\n> /folderA/sourcecode/\n> /folderA/sourcecode/file1.txt\n> /folderA/sourcecode/file2.txt\n> etc...\n> \n> When putting the project under git source control, I did this:\n> \n> cd /folderA\n> git init\n> \n> So now when colleagues clone my repository, they get the source code\n> in the \"sourcecode\" folder.  I'd like to just make the repository\n> simply give them the source files, not in a directory.  In other\n> words, as if I had originally been smart and done this:\n> \n> cd /folderA/sourcecode\n> git init\n> \n> Can I make that happen without losing all of the history?\n\ngit mv sourcecode/* .\nrmdir sourcecode\ngit commit\n\n-- \nShawn.\n"},{"id":"78662","messageId":"32541b130806041308y43a18b50s5dbca61f96a52823@mail.gmail.com","threadId":"13800","inReplyTo":"1086fb5f0806041303v7856404dxb95b5a450ac30ae1@mail.gmail.com","subject":"Re: move git repository out of a folder?","fromName":"Avery Pennarun","fromEmail":"apenwarr@gmail.com","sentAt":"2008-06-04T20:08:57Z","receivedAt":"2008-06-04T20:08:57Z","isPatch":false,"sender":{"key":"apenwarr@gmail.com","avatar":"https://avatars.githubusercontent.com/u/20592?v=4"},"body":"On 6/4/08, Sean Brown <seanmichaelbrown@gmail.com> wrote:\n>  So now when colleagues clone my repository, they get the source code\n>  in the \"sourcecode\" folder.  I'd like to just make the repository\n>  simply give them the source files, not in a directory.  In other\n>  words, as if I had originally been smart and done this:\n>\n>  cd /folderA/sourcecode\n>  git init\n>\n>  Can I make that happen without losing all of the history?\n\nYou could just make a commit which renames all the files into the\nparent folder.  This is relatively harmless and correctly reflects\nwhat really happened.\n\nYou might also want to look at git-filter-branch and its\n\"--subdirectory-filter\" option.\n\nHave fun,\n\nAvery\n"},{"id":"78665","messageId":"m31w3dyn2n.fsf@localhost.localdomain","threadId":"13800","inReplyTo":"20080604200724.GV12896@spearce.org","subject":"Re: move git repository out of a folder?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-06-04T20:14:42Z","receivedAt":"2008-06-04T20:14:42Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> Sean Brown <seanmichaelbrown@gmail.com> wrote:\n> >\n> > Let's say I've got this directory structure of source files:\n> > \n> > /folderA\n> > /folderA/sourcecode/\n> > /folderA/sourcecode/file1.txt\n> > /folderA/sourcecode/file2.txt\n> > etc...\n> > \n> > When putting the project under git source control, I did this:\n> > \n> > cd /folderA\n> > git init\n> > \n> > So now when colleagues clone my repository, they get the source code\n> > in the \"sourcecode\" folder.  I'd like to just make the repository\n> > simply give them the source files, not in a directory.  In other\n> > words, as if I had originally been smart and done this:\n> > \n> > cd /folderA/sourcecode\n> > git init\n> > \n> > Can I make that happen without losing all of the history?\n> \n> git mv sourcecode/* .\n> rmdir sourcecode\n> git commit\n\nWhat he said.  Git should automatically detect renames.  When pulling\ncode from someone who hasn't made this change yet, you might need to\nuse 'subtree' merge strategy, as currently git would put files added\nas sourcecode/filename in sourcecode/filename, not as top dir filename\nwhen pulling from side branch.\n\nIf you want to _change history_, as if you made correct decision at\nthe start (and convince everyone to reclone, or to do the same\nsurgery; or if you for the time being are solo contributor to the\nproject), you can use git-filter-branch (formerly cg-admin-rewrite-hist ;-).\n\nHTH\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"78666","messageId":"1086fb5f0806041318u3b1c4a3cg4dbc73fb638ea16b@mail.gmail.com","threadId":"13800","inReplyTo":"m31w3dyn2n.fsf@localhost.localdomain","subject":"Re: move git repository out of a folder?","fromName":"Sean Brown","fromEmail":"seanmichaelbrown@gmail.com","sentAt":"2008-06-04T20:18:29Z","receivedAt":"2008-06-04T20:18:29Z","isPatch":false,"sender":{"key":"seanmichaelbrown@gmail.com","avatar":"https://gravatar.com/avatar/6ff2a76c5b8cc3ee811b5c75c65ee629bbbf9a16ac61d06d9b7d223c38838c4e?d=mp&s=160"},"body":"On Wed, Jun 4, 2008 at 4:14 PM, Jakub Narebski <jnareb@gmail.com> wrote:\n> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n>\n>> Sean Brown <seanmichaelbrown@gmail.com> wrote:\n>> >\n>> > Let's say I've got this directory structure of source files:\n>> >\n>> > /folderA\n>> > /folderA/sourcecode/\n>> > /folderA/sourcecode/file1.txt\n>> > /folderA/sourcecode/file2.txt\n>> > etc...\n>> >\n>> > When putting the project under git source control, I did this:\n>> >\n>> > cd /folderA\n>> > git init\n>> >\n>> > So now when colleagues clone my repository, they get the source code\n>> > in the \"sourcecode\" folder.  I'd like to just make the repository\n>> > simply give them the source files, not in a directory.  In other\n>> > words, as if I had originally been smart and done this:\n>> >\n>> > cd /folderA/sourcecode\n>> > git init\n>> >\n>> > Can I make that happen without losing all of the history?\n>>\n>> git mv sourcecode/* .\n>> rmdir sourcecode\n>> git commit\n>\n> What he said.  Git should automatically detect renames.  When pulling\n> code from someone who hasn't made this change yet, you might need to\n> use 'subtree' merge strategy, as currently git would put files added\n> as sourcecode/filename in sourcecode/filename, not as top dir filename\n> when pulling from side branch.\n>\n> If you want to _change history_, as if you made correct decision at\n> the start (and convince everyone to reclone, or to do the same\n> surgery; or if you for the time being are solo contributor to the\n> project), you can use git-filter-branch (formerly cg-admin-rewrite-hist ;-).\n>\n\nThank you Shawn and Jakub.  This worked perfectly.\n\nSean\n"}]}