从git存储库中拆分一个包含所有分支和历史记录的子文件夹

sha*_*sha 2 git version-control github bitbucket

我想将我的git存储库中的文件夹拆分为新文件夹.但我想保留所有与此文件夹相关的所有打开/关闭分支和历史记录.

\ Source Repo
--\ AAA
--\ BBB
----\ DDD
----\ EEE
--\ CCC


\ New Repo 1
--\ AAA
--\ CCC

\ New Repo 2 (BBB subfolder)
--\ DDD
--\ EEE
Run Code Online (Sandbox Code Playgroud)

我按照此处描述的步骤https://help.github.com/articles/splitting-a-subfolder-out-into-a-new-repository/ - 但这仅适用于单个分支.最后 - 我获得了所有(?)提交的新存储库,但没有分支信息.

我尝试使用--all参数为所有分支执行此操作,但我不清楚如何将所有重写的分支推送到空的远程仓库.

这是我目前的情况:

$ git clone https://github.com/USERNAME/REPOSITORY-NAME
$ cd REPOSITORY-NAME
$ git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME -- --all
Run Code Online (Sandbox Code Playgroud)

在这一点上,如果我看看我的本地回购,我似乎有所有历史和所有分支在遥控器的起源.

$ git remote -v
origin  https://github.com/USERNAME/REPOSITORY-NAME.git (fetch)
origin  https://github.com/USERNAME/REPOSITORY-NAME.git (push)
$ git remote set-url origin https://github.com/USERNAME/NEW-REPOSITORY-NAME.git
$ git remote -v
origin  https://github.com/USERNAME/NEW-REPOSITORY-NAME.git (fetch)
origin  https://github.com/USERNAME/NEW-REPOSITORY-NAME.git (push)


$ git push -u origin --all 
Run Code Online (Sandbox Code Playgroud)

最后一个命令似乎没有推动所有分支.我错过了什么?

sha*_*sha 8

在这里发现缺少的信息Detach(move)子目录到单独的Git存储库中

完成的脚本看起来像这样.将此过程用于两个新存储库,其中一行不同

克隆源存储库:

$ git clone https://github.com/USERNAME/REPOSITORY-NAME
$ cd REPOSITORY-NAME
Run Code Online (Sandbox Code Playgroud)

在本地重新创建所有远程分支

$ for i in $(git branch -r | sed "s/.*origin\///"); do git branch -t $i origin/$i; done
Run Code Online (Sandbox Code Playgroud)

使用filter-branch修剪所需子文件夹的所有内容(这将仅使用FOLDER-NAME创建新的repo

$ git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME -- --all
Run Code Online (Sandbox Code Playgroud)

使用filter-branch删除FOLDER-NAME(这将创建除FOLDER-NAME之外的所有内容的新存储库)

$ git filter-branch --prune-empty --tree-filter 'rm -rf FOLDER-NAME' -- --all
Run Code Online (Sandbox Code Playgroud)

将远程URL更新为新的空仓库:

$ git remote -v
origin  https://github.com/USERNAME/REPOSITORY-NAME.git (fetch)
origin  https://github.com/USERNAME/REPOSITORY-NAME.git (push)
$ git remote set-url origin https://github.com/USERNAME/NEW-REPOSITORY-NAME.git
$ git remote -v
origin  https://github.com/USERNAME/NEW-REPOSITORY-NAME.git (fetch)
origin  https://github.com/USERNAME/NEW-REPOSITORY-NAME.git (push)
Run Code Online (Sandbox Code Playgroud)

推动一切

$ git push -u origin --all
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

829 次

最近记录:

8 年,10 月 前