几个月前,我开始了一个项目,并将所有内容都存储在主目录中。在我的主目录“项目”中,有几个子目录包含不同的内容:项目/纸张包含一个用LaTeX编写的文档项目/源代码/LaTeX应用程序包含我的rails应用程序。
“项目”是GITified,在"paper“和"RailsApp”目录中都有很多提交。现在,当我想对我的"RailsApp“使用cruisecontrol.rb时,我想知道是否有一种方法可以在不丢失历史的情况下从"RailsApp”中创建子模块。
发布于 2019-02-19 04:28:42
CoolAJ86和apenwarr的答案非常相似。我在两者之间来回奔波,试图理解其中任何一个中缺失的部分。下面是它们的组合。
首先,导航Git Bash到要拆分的git代码库的根目录。在我的示例中,它是~/Documents/OriginalRepo (master)
# 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)
# 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
https://stackoverflow.com/questions/920165
复制相似问题