git 子仓库
主仓库中添加子仓库
git submodule add <url> <path>
更新子代码代码
git submodule update --init
克隆含有子仓库的仓库
git clone --recurse-submodules <url>
主仓库中删除子仓库
1、进入包含子仓库的父仓库的根目录
2、使用以下命令将子仓库从父仓库中移除(解除关联)
git submodule deinit <submodule_path>、
3、使用以下命令从 Git 仓库中删除子仓库的记录
git rm <submodule_path>
4、执行 git commit 来提交父仓库的修改
git commit -m "Remove submodule <submodule_path>"
5、最后,删除实际的子仓库文件。你可以手动删除相关的子目录,或者使用以下命令删除子仓库目录:
rm -rf <submodule_path>
子仓库 push 提交到 gerrit 出现没有 change-id ?
由于子仓库在 clone
后,仓库的 .git
目录中,没有 hook/commit-msg
工具
所以在生成的 commit message
中,不会自动增加change-id
这会导致 commit
无法 push
到 gerrit
上走 review
的流程
请使用以下方法增加 commit-msg tool
到子仓库的 .git
目录中:
cd `awk '{printf $2}' .git`/hooks
wget http://192.168.0.202:8002/tools/hooks/commit-msg
chmod +x commit-msg
cd -
对于没有 change-id
的 commit
可以使用 git commit --amend
或者 git rebase -i
重新增加 change-id
有了 change-id
后即可以顺利 push