| name | devops-submodule |
| description | 管理 Git 子模块的完整生命周期:添加、移除、更新、修复冲突、查看状态。处理 detached HEAD、合并冲突等边缘情况。 |
devops-submodule
管理 Git 子模块(添加、移除、更新、修复)。
规则
- 最小干预:仅执行用户明确请求的操作
- 原子提交:每个子模块变更独立提交
- 验证优先:操作后运行
git status 和 git submodule status 确认
- 子模块可能进入 detached HEAD 状态,提交前需切换到 main 分支
子命令
add - 添加子模块
git ls-remote <url> HEAD
git submodule add <url> <path>
git add <path>
git commit -m "feat: add <name> submodule"
remove - 移除子模块
git submodule deinit -f <path>
git rm -f <path>
gh repo delete <owner>/<repo> --yes
git config --file .git/config --remove-section submodule.<name>
git commit -m "chore: remove <name> submodule"
update - 更新子模块
git submodule status
git submodule update --init <path>
git submodule update --remote <path>
git -C <path> status
git -C <path> checkout main
git -C <path> pull
git add <path>
git commit -m "chore: update <name> submodule"
git push --recurse-submodules=on-demand
fix - 修复子模块冲突
git merge --abort
git pull --no-rebase --no-recurse-submodules
git -C <path> add -A
git -C <path> commit -m "fix: resolve merge conflict"
git add <path>
git commit -m "fix: resolve <name> submodule conflict"
status - 查看状态
git status
git submodule status