git 添加更新子模块

添加submodule到仓库

下载父仓库:

git clone git@gitlab.abc.com:cloud-security-platform/console-after.git

父仓库中添加submodule,分支可以指定对应的submodule分支,以master为例:
进入submodule所在目录:

 cd src/main/webapp/

下载submodule对应的master分支:

git submodule add -b master git@gitlab.abc.com:cs70/console-before.git console
或者(默认就是master)
git submodule add  git@gitlab.abc.com:cs70/console-before.git console

将submodule提交到本地库:

git commit -am "add submodule console"

将subodule推送到线上库:

 git push origin master

命令执行完成会发现生成了一个.gitmodules文件,可以修改该文件中代码的地址

更新submodule

更新操作跟普通的项目操作一样:
进入submodule所在目录(/src/main/webapp/console)
git pull从远程获取最新版本merge到本地
git branch -a 查看所有submodule版本
git branch -vv 查看当前head对应的远程分支
git checkout 对应分支版本
git commit -am “更改功能点说明”
git push origin “远程分支” [以master分支为例:git push origin master]

问题记录

由于第一次操作,出现了以下错误提示:

A git directory for 'console' is found locally with remote(s):
  origin        [email protected]:cs70/console-before.git
If you want to reuse this local git directory instead of cloning again from
  [email protected]:cs70/console-before.git
use the '--force' option. If the local git directory is not the correct repo
or you are unsure what this means choose another name with the '--name' option.

解决方法:

git submodule add --name Common git@gitlab.abc.com:cs70/console-before.git console

猜你喜欢

转载自blog.csdn.net/chang_li/article/details/79568509