git submodule 子仓库使用

git仓库嵌套子仓库使用方案

  • 话不多说,直接贴代码
git clone https://father.git
cd father
# 子仓库1
git submodule add http://child1.git
git status
git commit -am "add child1"
git pull origin branch
git push origin branch
# 子仓库2
git submodule add http://child2.git
git commit -am "add child2"
git pull origin branch
git push origin branch
  • 如果git submodule 过程中遇到问题如
warning: adding embedded git repository: 子仓库name
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint: 
hint:     git submodule add  子仓库name
hint: 
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint: 
hint:     git rm --cached 子仓库name
  • 这个时候就证明你没有submodule add 成功,需要将缓存中的清除。
git rm --cached 子仓库name,此时如果报错如下:
# error
fatal: not removing 'module-name' recursively without -r
# 将命令修改成
git rm -r --cached module-name
  • submodule add 成功之后 git status 查看可看到 new file .gitmodules
  • 这个时候证明成功了。

关于子仓库的使用希望能帮到你,有问题可以留言。

你可能感兴趣的:(git)