git sub-library related operations

1. Git creates a sub-library in the main library

1、进入主库目录
2、git submodule add 子库链接 子库文件夹
	备注:子库文件夹会被新建。如果是要链接子库的其他分支,在本条命令完成之后进入子库切换分支(git branch -a可以查看所有分支),然后退回主库目录操作
3、git status
	回到主目录查看缓存区文件,可以看到.gitmoudle文件和新增了子库文件
4、做一笔提交提交到主库分支,子库链接建立完毕

2. Download all library code

有子库之后,每次下载代码都要和子库一起下
第一种方法:
git clone --recursive 主库链接
直接添加参数下载的同时会子库代码一起下载完毕
第二种方法:
git clone 主库链接
git submodule init
git submodule update 某个子库链接
这种方法可以只下载某个子库,不加子库链接,默认下载所有子库

3. When there is a code update in the sub-library, the main library will update the code

子库代码更新之后,主库代码也要更新提交,保证代码最新
1、进入子库目录
2、git fetch
3、git merge origin/master
	同步主干代码,也可直接进入子库目录使用git pull更新代码,这个方法我这边没有尝试,理论可行
4、进入主库代码
5、git diff
	可以查看到刚刚子库更新之后主干代码对子库代码的commitID有修改
6、提交主库代码就行

Guess you like

Origin blog.csdn.net/weixin_44440669/article/details/127534235