我有一个包含多个分支的应用程序的git存储库。源树由几个目录组成。例如:
main_folder
|--> .git
|--> dir0
|--> dir1
|--> dir2不幸的是,从开发一开始,我就没有使用git-submodules或git-subtree。现在我想将其中一个目录(例如dir0 )作为一个新的独立应用程序移到一个新的存储库中,当然,如果可能的话,我希望保留相应目录的历史记录和分支。
所以我有两个问题:
发布于 2015-02-26 02:23:56
git splits 使用
它基本上使用相同的git filter-branch方法,但具有更简单的接口。
git splits。我在杰克廷解的基础上作为git扩展创建了它。#change into your repo's directory cd /path/to/repo #checkout the branch git checkout MyOldBranch #split directory or directories into new branch git splits -b MyNewBranch dir1 dir2 dir2...如果您想要的只是将目录及其历史复制到新的分支,请在这里停止(您已经完成了)。
如果您希望将新的分支推送到独立的回购协议()
new_repo on GitHub的空回购,它有path:git@github.com:simpliwp/new_repo.git#add a new remote origin for the empty repo so we can push to the empty repo on GitHub git remote add origin_new_repo git@github.com:simpliwp/new_repo.git #push the branch to the new repo's master branch git push origin_new_repo new_repo:master#change current directory out of the old repo cd /path/to/where/you/want/the/new/local/repo #clone the remote repo you just pushed to git clone git@github.com:simpliwp/new_repo.git发布于 2015-02-23 13:55:56
试试git subtree split。这可以拆分一个子文件夹并保留历史记录。
关于如何使用它,请参考手册页。
发布于 2015-02-25 23:40:32
最后,我使用了git filter-branch方法,Github也提到了这一点。
程序如下。
cd到新目录dir0的新存储库,相应的git命令应该是:
git filter-branch --prune-empty --subdirectory-filter dir0 masterdir0除外。此外,它将删除与‘dir0 0’无关的提交,这非常方便。dir0并提交即可。https://stackoverflow.com/questions/28583470
复制相似问题