Git Subtree 的使用

来源:互联网 发布:西安汇知中学四大恶霸 编辑:程序博客网 时间:2024/05/27 21:48

Git Subtree 的使用

1、创建 subtree
git remote add -f <子仓库名> <子仓库git地址>
git subtree add --prefix=<子目录名> <子仓库名> <分支> --squash
1. 其中 -f 的意思是在添加远程仓库之后,立即执行fetch;
2. –squash 意思是把 subtree 的改动合并成一次 commit ,这样就不用拉去子项目完整的历史记录。–prefix 之后的 “=”也可以用空格代替。
git remote add -f Utils https://github.com/KoKoBoom/CommonUtils.git
git subtree add --preifx=Taki.Utils Utils mater --squash
2、从远程仓库更新子目录
git fetch <子仓库名> <分支>
git subtree pull --prefix=<子目录名> <子仓库名> <分支> --squash
:
git fetch Utils master
git subtree pull --prefix=Taki.Utils Utils master --squash
3、从子目录 push 到远程仓库
git subtree push --prefix=<子目录名> <子仓库名> master
git subtree push --prefix=Taki.Utils Utils master
本条命令实际是根据【【主项目.git】的子目录】更新你的引用的【子项目.git】,并不会把你本地的子目录push到你的【子项目.git】。所以执行此代码前,你最好提交了你项目的【所有更新】。
如果你用本条代码 push 不了,那么你就要执行一次【代码2】 然后解决冲突,再重新提交。

http://aoxuis.me/post/2013-08-06-git-subtree

0 0