Git 工程拆分
原创2020/8/3...小于 1 分钟
原仓库目录:
--source
|-one
|-two现在要新建一个仓库:
--target
|-one并保留commit
1. clone原仓库
$ git clone git@github.com:user/source.git
$ cd source2. 把one目录及相关提交记录抽取到新的分支temp
--annotate 参数会在所有commit message上追加前缀,用于区分提交记录的来源
$ git subtree split -P one --annotate='(from source)' -b temp3. 另建一个新目录并初始化为 git 仓库
$ mkdir ../target
$ cd ../target
$ git init4. 拉取原仓库的 temp 分支到当前的 master 分支
--allow-unrelated-histories 如果target仓库是非空的,存在提交记录,则会报错fatal: refusing to merge unrelated histories,需要添加该参数
$ git pull ../source temp --allow-unrelated-histories