简体   繁体   中英

How can I un-nest a Git repository

I accidentally did a git.init on a parent folder of my app (Rails project). I didn't realise until a long way into my development when I now wish to deploy to Heroku.

My folder structure is ~/project/project/app with git initialised in ~/project/app .

Heroku states:

" Heroku apps expect the app directory structure at the root of the repository. If your app is inside a subdirectory in your repository, it won't run when pushed to Heroku. "

So, I'm trying to undo this, without much success.

I tried moving all the folders of my app up a level, so from project/ I did the following command:

mv project/* project/.* .

This seemed to move a copy of everything up a level, into my ~/project folder, however, in terms of Git, only the still nested files (in ~/project/project/) are the branch specific files (as tested by switching branches and looking at both sets of files in my text editor).

I copied the files when my git branch was specified as the master branch. Does this mean I've only copied the "master branch" files. This is where my knowledge of git is limited.

Any help much appreciated.

** note, i have a copy of my folder or can re-clone from github.

If you don't have a problem to re-publish your repo ( git push --force , meaning you will change the history of commits, and other will have to fetch and reset their local branches), you can refer to " How can I move a directory in a Git repo for all commits? ".

Use git filter-branch in order to affect all commits of all branches:

git filter-branch --tree-filter \
  'test -d project/app && mv project/app . || echo "Nothing to do"' HEAD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM