本文主要是介绍GIT中对子仓库的使用方法介绍,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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
拉取子仓库时,避免重复输入用户名和密码
git config --global http.postBuffer 524288000
在父仓库根目录中执行
git submodule update --remote
该命令会根据 .gitmodules 中每个子仓库的分支,同步至远程仓库对应分支的最新节点。
(所以请确保 .gitmodules 每个子仓库的分支名是正确的)
这篇关于GIT中对子仓库的使用方法介绍的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!