首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何提取git子目录并从中生成子模块?

如何提取git子目录并从中生成子模块?
EN

Stack Overflow用户
提问于 2009-05-28 10:18:42
回答 1查看 32.8K关注 0票数 123

几个月前,我开始了一个项目,并将所有内容都存储在主目录中。在我的主目录“项目”中,有几个子目录包含不同的内容:项目/纸张包含一个用LaTeX编写的文档项目/源代码/LaTeX应用程序包含我的rails应用程序。

“项目”是GITified,在"paper“和"RailsApp”目录中都有很多提交。现在,当我想对我的"RailsApp“使用cruisecontrol.rb时,我想知道是否有一种方法可以在不丢失历史的情况下从"RailsApp”中创建子模块。

EN

回答 1

Stack Overflow用户

发布于 2019-02-19 04:28:42

CoolAJ86apenwarr的答案非常相似。我在两者之间来回奔波,试图理解其中任何一个中缺失的部分。下面是它们的组合。

首先,导航Git Bash到要拆分的git代码库的根目录。在我的示例中,它是~/Documents/OriginalRepo (master)

代码语言:javascript
复制
# move the folder at prefix to a new branch
git subtree split --prefix=SubFolderName/FolderToBeNewRepo --branch=to-be-new-repo

# create a new repository out of the newly made branch
mkdir ~/Documents/NewRepo
pushd ~/Documents/NewRepo
git init
git pull ~/Documents/OriginalRepo to-be-new-repo

# upload the new repository to a place that should be referenced for submodules
git remote add origin git@github.com:myUsername/newRepo.git
git push -u origin master
popd

# replace the folder with a submodule
git rm -rf ./SubFolderName/FolderToBeNewRepo
git submodule add git@github.com:myUsername/newRepo.git SubFolderName/FolderToBeNewRepo
git branch --delete --force to-be-new-repo

下面是上面的副本,替换了可自定义的名称,并使用https。根文件夹现在为~/Documents/_Shawn/UnityProjects/SoProject (master)

代码语言:javascript
复制
# move the folder at prefix to a new branch
git subtree split --prefix=Assets/SoArchitecture --branch=so-package

# create a new repository out of the newly made branch
mkdir ~/Documents/_Shawn/UnityProjects/SoArchitecture
pushd ~/Documents/_Shawn/UnityProjects/SoArchitecture
git init
git pull ~/Documents/_Shawn/UnityProjects/SoProject so-package

# upload the new repository to a place that should be referenced for submodules
git remote add origin https://github.com/Feddas/SoArchitecture.git
git push -u origin master
popd

# replace the folder with a submodule
git rm -rf ./Assets/SoArchitecture
git submodule add https://github.com/Feddas/SoArchitecture.git
git branch --delete --force so-package
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/920165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档