将git存储库上移一个层次结构级别 [英] Moving a git repository up one hierarchy level

查看:178
本文介绍了将git存储库上移一个层次结构级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git初学者问题:

我有一个小型私人web项目,它使用msysgit在本地版本化。没有外部存储库,因为它只适用于我,所以我可以bascially做任何我想要的。



我已经在项目目录中设置了它,即在webroot。

现在必须创建第二个目录,并放置在与webroot平行的位置。让我们称之为资产。



因此,结构如下:

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

我希望将这个新目录包含在git存储库中,以便我还可以对存储在那里的文件进行版本更改,但我当然不能使用git add ../assets。我也不想在project_directory中创建一个新的git项目,因为这会丢失我以前的所有提交。

那么我该如何将存储库移出webroot up intoproject_directory,同时保留我的提交,然后能够包含资产?

解决方案

你的git回购看起来像这样:

 < projectdir> 
/.git
/ webroot
/资产

这个,你必须将你的repo中的现有文件移动到一个新的 webroot 子目录中。

  cd< git repo root> 
mkdir webroot
git mv<所有文件> webroot
git commit --all -m将所有现有文件移动到新的'webroot'目录

然后,在你的本地文件系统上,你想把你的克隆一个目录重定位到它现在的位置:

  cd< PROJECTDIR> 
mv webroot / *。
rmdir webroot

然后,您要添加资产目录(和文件)到git仓库:

  git添加资产
git commit -m 将资产添加到回购


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"?

解决方案

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"

这篇关于将git存储库上移一个层次结构级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆