| name | devops-commit |
| description | Git 提交技能,用于提交代码变更时,包括主仓库和子模块提交。 |
Git 提交技能
提交规范
使用 Conventional Commits 规范:
<type>: <description>
提交类型
- feat:新功能
- fix:修复 bug
- docs:文档更新
- test:测试相关
- refactor:代码重构
- chore:构建/工具
提交示例
git commit -m "feat: 添加新功能"
git commit -m "fix: 修复登录问题"
git commit -m "docs: 更新 README"
提交流程
1. 同步远程
git fetch && git pull
若产生冲突:
git status
git add <resolved-file>
git rebase --continue
git merge --continue
2. 检查状态
git status
查看未提交的变更,包括:
- 未暂存的修改(Changes not staged for commit)
- 已暂存的修改(Changes to be committed)
3. 添加文件
git add <file>
git add -A
4. 提交
git commit -m "<type>: <description>"
5. 确认
git status
确认提交成功,当前分支应领先 origin/main n 个提交。
6. 推送
git push
子模块提交
1. 子模块内提交
cd docs/handbook
git status
git add -A
git commit -m "docs: 更新文档"
git push
2. 主仓库更新子模块引用
cd ../..
git add docs/handbook
git commit -m "chore: update handbook submodule"
git push
常见场景
场景一:普通代码提交
git add -A
git commit -m "feat: 添加用户认证功能"
git push
场景二:文档更新
git add docs/README.md
git commit -m "docs: 更新使用说明"
git push
场景三:子模块更新
cd docs/gallery
git add -A
git commit -m "docs: 添加新示例"
git push
cd ..
git add docs/gallery
git commit -m "chore: update gallery submodule"
git push