是否有可能在另一个git仓库中拥有一个git仓库 [英] Is it possible to have a git repo inside another git repo

查看:237
本文介绍了是否有可能在另一个git仓库中拥有一个git仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用git管理的django项目。我是git推送给我的主机。现在,我希望能够将其中一个目录(包括所有子目录)推送到另一个git库。编辑:所以我希望这个目录本身就是一个git仓库。


$ b

你可以看看git的支持子模块。您可以将第二个存储库作为子模块添加到主项目中,例如使用如下命令:

$ g $ sub $ g $ g $ git submodule add git://wherever/blah.git库代码
git commit - m添加了一个名为'library-code'的新子模块

当您更改 library-code 子目录,就好像父库不存在 - 你可以改变 origin 来使用你可以使用的传输



要指定您希望子模块处于特定版本,您应该更改为子模块,并使用 git checkout 切换到正确的版本。然后你改回到主存储库和stage并提交新的子模块版本:

  git add library-code 
git commit -m'更改子模块版本'

主存储库的树只存储子模块应该位于的版本,所以当你推送主存储库时,它不会推送子模块中的任何文件。



为了拆分这个子目录,同时保留历史记录,您需要克隆原始存储库和用户 git filter-branch 以重写历史记录,如本答案中所述:



然后,您可以将其推送到新创建的存储库GitHub存储库,返回到您的原始项目,删除子目录并将其替换为子模块如上所述。 p>

如果你对git概念不熟悉,那么这可能对你很困难 - 我建议事先阅读git submodules。


I have a django project managed with git. I am git pushing it to my host. Now, I want to be able to push just one of the directories (inc. all sub dirs) to another git repo. How is it possible, if it is possible at all?

Edit: So I want that directory to be a git repo itself.

解决方案

You could look at git's support for submodules. You would add the second repository as a submodule to your main project, e.g. with commands like:

git submodule add git://wherever/blah.git library-code
git commit -m "Added a new submodule called 'library-code'"

When you change into the library-code subdirectory, it's as if the parent repository doesn't exist - you can change origin to use a transport that you can push over and then push as if it were completely independent.

To specify that you want the submodule to be at a particular version, you should change into the submodule and use git checkout to switch to the right version. Then you change back up to the main repository and stage and commit that new submodule version with:

git add library-code
git commit -m 'Change the submodule version'

The tree of the main repository just stores the version that the submodule should be at, so when you push the main repository, it's not pushing any of the files in the submodule.

In order to split off this subdirectory, while preserving history, you'll need to clone your original repository and user git filter-branch to rewrite the history, as described in this answer:

Then you can push that to a newly created repository GitHub repository, return to your original project, remove the subdirectory, and replace it with the submodule as described above.

If you're not very familiar with git concepts then this may be difficult for you - I would recommend reading up on git submodules beforehand.

这篇关于是否有可能在另一个git仓库中拥有一个git仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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