所以现在我有了这个文件夹结构:
frontend
-- .git/
-- project 1 folder
-- project 2 folder
现在,我们决定将每个项目在其自己的存储库中分开,并为每个项目更改远程URL。
我该如何制作它,以免破坏我对project 1 folder
的提交历史记录,但是下次我进行git push
时,根文件夹现在为project 1 folder
而不是frontend
?
我看到了这个类似的问题,但是被接受的答案似乎是错误的(root文件夹仍包含在提交中(
我认为您链接到的答案确实是您想要的:向下移动git存储库
也许不清楚的是如何将其准确地应用于您的情况下,因为您正在向上移动而不是向下移动。因此,这里适合您的情况:
# start with a fresh clone because you don't want any "dirty" files here!
git clone <remote>/frontend.git
# enter the fresh clone
cd frontend
# remove project 2 files
rm -rf "project 2 folder"
# move project 1 files up
mv "project 1 folder"/* .
rmdir "project 1 folder"
# create massive change commit
git add -A
git commit -m "Moved project 1 up and removed project 2"
git push
现在,所有这些所在的文件夹frontend
实际上不是存储库本身的一部分,而是其所在的名称。下一个克隆时,您可以重命名:
git clone <remote>/frontend.git "project 1 folder"
只会更改该克隆的名称。
或者,您可以使用git服务器,并将存储库本身重命名为"项目1文件夹"。当然,这样做将使任何人从该仓库中克隆过的任何沙箱的远程URL无效,因此您必须修复这些。
现在,问题是项目2已经消失了。我认为您可能需要做的是在每个项目上创建两个新的存储库。按照上述步骤,在git push
之前停止,然后执行此操作:
# Create "project 1 folder".git on your Git server and add it as a second remote
git remote add p1 <remotes>/"project 1 folder".git
# push to that remote instead of origin - list all branches you want to preserve
git push p1 master
重复上述所有内容,扭转了项目1和2的角色。