How do I "unnest" git folders?
I have a component, which was uploaded into GitLab. I want to include part of that code into a brand new GitLab repo.
When I include a /code/ folder into a new Git repo, it's tells me that the folder is in a Nested Root
state. I'm using SmartGit, where it seems to show a bundle for the files, instead of individual folders & files.
When I try to add it into GitLab using SmartGit, it want's to create a Sub-Module to my original component, which is also in GitLab. I don't really want to link it between the current /cleanRepo/
and any /existingRepo/
. I know that SVN used to have a lot of hidden .properties files. Git seems to have those as well. So I probably need to make it forget about all of the previous repo's Git information.
Backstory / Reason: I want to re-use some of a finished component's code in all of my brand new components, which I want to build in the future. I don't want to copy & paste a fully built component's code into a new folder, whenever I clone a new repository & want to build a new component. I don't want to have to delete what shouldn't be in that new component, every time that I make a new component. So I want to create a clean repository with a master copy of the starting code. Let's say it contains 1/3 of a fully-built component's code. I'm going to copy that clean/master code folder into each new Git repository folder. Then I'm going to go into my new component's folder to extend the copied code in that folder. This would make a nice clean cookie cutter approach to building new components, where I can avoid deleting a plethora of files & editing multiple files, to delete large swathes of code.
Ideal Example:
cd /cleanRepo/code/
cp -R ./* ~/someNewFolder
cd ~/someNewFolder
^-- start editing that code, but don't edit any /cleanRepo/code/
Is there an easy way to "unnest" git folders? I want to see a list of folders & files, that I'd like to include. Not a "Nested Root" bundle.
Yes there is an easy way to do this! I just figured it out after my 2nd cup of coffee. Using these commands will allow all of the files to be displayed in SmartGit as an unrolled list of files. Then they can be individually included, instead of being bundled as a Nested Root
sub-module.
cd /cleanRepo/code/
ls -a
rm -rf .git*
find . -exec touch {} \;
So if anyone else runs into this issue, that's how to solve it.
Btw, using ls -a
shows this list of hidden files:
.
..
.editorconfig
.eslintignore
.eslintrc
.git
.gitattributes
.gitignore
.gitlab-ci.yml
.npmignore
Just make sure that you don't use rm -rf *.*
as it will forcibly & silently delete everything!
There is 1 thing that I noticed about the files. In some folders, I had to go into them & do the following, to get the sub-folders to appear in SmartGit:
cd /subfolder/
touch abc
rm abc
That allows the files with sub-folders to appear as individual files.
I've added a way to automate that sub-directory traversing & touching process, without having to write a script for it. It's the find . -exec touch {} \;
line above. If that doesn't work for you, then go into a sub-folder, touch a file (or create a new one + delete it) & then the files will appear!