一、 1.在子目录所在的父级Git存储库中创建一个新的分支,用于分离子目录。使用git checkout -b branch-name命令创建并切换到新分支。 2.使用git filter-branch --subdirectory-filter path/to/subdirectory命令来提取子目录。其中,path/to/subdirectory是你想要分离的子目录的路径。 3.Git会重新写入历史记录,仅保留与子目录相关的提交和文件。默认情况下,Git会删除原父级Git存储库中与子目录无关的提交。如果还需要保留其他提交记录,请使用--prune-empty参数。 4.完成上述步骤后,你将得到一个仅包含子目录的新Git存储库。 5.使用git remote add origin <new-repository-url>来将远程仓库的地址添加到新Git存储库中。 6.使用git push -u origin master命令将子目录的内容推送到新仓库,并将其设置为默认分支。 二、 # Step 1: 创建新分支 git checkout -b separate-repo # Step 2: 分离子目录 git filter-branch --subdirectory-filter src # Step 3: 保留其他提交记录 git filter-branch --subdirectory-filter src --prune-empty # Step 4: 添加远程仓库地址 git remote add origin <new-repository-url> git remote add other <本地仓库路径> //除了可以同步远程仓库,还可以同步到本地 # Step 5: 推送到新仓库 git push -u origin master |
|小黑屋|
飞凌嵌入式
( 冀ICP备12004394号-1 )
GMT+8, 2025-6-23 15:02
Powered by Discuz! X3.4
© 2001-2013 Comsenz Inc.