Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

Moving a git repository up one hierarchy level

Git beginner question:

I have a small private webproject which is versioned locally with msysgit. There is no exterior repository, as it's only for me, so i can bascially do whatever I want.

I've had this set up in the project directory, ie in "webroot".

Now a second directory had to be created, placed parallel to webroot. Let's call it assets.

So structure is now as follows:

 project directory
----webroot
----assets

I'd love to include this new directory in the git repository, so that I'd also version changes to files stored there, but of course I can't use "git add ../assets". Neither am I inclined to create a new git project in project_directory, as this would loose all my previous commits.

So how do I go about moving the repository out of "webroot" up into "project_directory", while keeping my commits and then being able to include "assets"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

So, you want your git repo to look like this:

<projectdir>
    /.git
    /webroot
    /assets

To do this, you must move the existing files in your repo into a new webroot subdirectory.

cd <git repo root>
mkdir webroot
git mv <all your files> webroot
git commit --all -m "moved all existing files to new 'webroot' directory"

Then, on your local filesystem you want to relocate your clone one directory above where it is now:

cd <projectdir>
mv webroot/* .
rmdir webroot

Then you want to add the assets directory (and files) to the git repo:

git add assets
git commit -m "added assets to the repo"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...