您阅读过子树文档吗?
split [<local-commit>]
Extract a new, synthetic project history from the history of the <prefix> subtree of <local-commit>,
or of HEAD if no <local-commit> is given. The new history includes only the commits (including
merges) that affected <prefix>, and each of those commits now has the contents of <prefix> at the
root of the project instead of in a subdirectory. Thus, the newly created history is suitable for
export as a separate git repository.
听起来像你想要的。
这是一个有效的例子;
初始化一个演示仓库;
mkdir subtree-split
cd subtree-split/
git init
git commit -m "Init." --allow-empty
为项目A添加一些内容;
mkdir A
touch A/README.txt
git add A/
git commit -m "Readme for A."
为项目B添加一些内容;
mkdir B
touch B/README.txt
git add B/
git commit -m "Readme for B."
将B拆分为新的子树;
git subtree --prefix=B/ split
创建一个新的存储库,仅将 B 的历史推送到;
cd ..
mkdir subtree-B
cd subtree-B
git init
git commit -m "Init subtree-B." --allow-empty
将子树B历史推送到远程;
cd ../subtree-split/
git subtree --prefix B/ push ../subtree-B HEAD
查看B的历史记录;
cd ../subtree-B
git log --all --pretty=oneline --abbrev-commit
a26e5de (HEAD -> master) Init subtree-B.
0523c62 (HEAD) Readme for B.
没有 A 的历史!