业务场景一、Git Submodule :
业务场景:项目中经常会使用到第三方的 git 库, 将三方库整合到自己项目中, 但是如果这个库升级了一个很酷炫的功能,我们需要获取它的最新代码
1、添加第三方库关联,作为一个submodule,子库
$ git submodule add https://github.com/pingcc/MyApplication.git
2、查看是否关联成功
$ git status
On branch master
Your branch is up to date with 'origin/master'.Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: .gitmodules
new file: MyApplication
3、更新子库代码、多个库更新 master分支
$ git submodule foreach MyApplication
$ git submodule foreach git checkout master
4、删除关联:
$ git submodule deinit MyApplication
error: the following file has changes staged in the index:
mall4j-bbc
(use --cached to keep the file, or -f to force removal)
fatal: Submodule work tree 'MyApplication' contains local modifications; use '-f' to discard them
报错执行:
$ git rm MyApplication -f
业务场景二、Git Remote
业务场景:基于第三方代码(开源代码)二次开发,第三方代码随时会更新(如:修复bug,增加功能),
此时自己公司团队正在二次开发(需求:需要更新第三方代码,并且将代码合并到自己公司代码),此时会有两个仓库并存,不同团队开发,适用此功能。
1、克隆仓库地址代码
$ git clone https://github.com/pingcc/MyApplication.git
2、cd MyApplication 目录下
3、关联远程仓库
$ git remote add d-master https://github.com/pingcc/MyApplication1.git
这时关联仓库会出现两个地址
拉下代码即可,合并到自己需要的分支上