SuperAPI AI 工具集

git

通用与其它

查看项目

更新于 10-15 20:31

技能介绍

用途:提供 Git 版本管理的最佳实践与工作流规范,适用于编写提交信息、创建与管理分支、创建和合并 PR,以及处理 Git 历史与冲突等场景。

主要能力:

  1. 提交信息规范:采用 Conventional Commits,格式为 <type>: <description>,类型包括 feat、fix、docs、style、refactor、test、chore、perf;可选详细格式为 <type>(<scope>): <subject>,并含 body 与 footer。约定首行 50 字以内、使用现在时与祈使语气、首字母小写、句末不加句号、body 每 72 字换行、说明变更原因(Why > What)、正文用英文。
  2. 分支工作流:基于 GitHub Flow,main 保持可部署;新仓库默认分支用 main(git init -b main,或用 git config --global init.defaultBranch main 全局设置)。分支命名格式 <type>/<description>,如 feature/、fix/、refactor/、docs/、test/、chore/ 前缀。常用流程:git switch main、git pull origin main、git switch -c feature/...、git add .、git commit、git push origin 分支。
  3. PR 与合并:用 gh pr create 创建 PR,gh pr merge <PR号> 配合 --squash、--merge 或 --rebase;功能分支推荐 Squash,发布分支用 Merge,需线性历史用 Rebase。
  4. 历史管理:git rebase -i HEAD~3 交互式整理(pick、reword、edit、squash、fixup、drop);git rebase main 同步主分支;git cherry-pick;git commit --amend 修改最后提交;区分 reset(--soft/--mixed/--hard)与 revert,已推送的提交应用 revert 而非 reset。
  5. 冲突解决:git status 查看冲突文件,手动处理 <<<<<<<、=======、>>>>>>> 标记后 git add,再用 git merge --continue 或 git rebase --continue;可用 git restore --ours/--theirs 选择一侧,或用 git merge --abort / git rebase --abort 取消。
  6. 日常命令:git switch 切换分支(Git 2.23+),git restore 恢复文件,git status/log/diff/show 查看状态,git stash 暂存,git remote/fetch/pull/push 管理远程。
  7. GitHub CLI:gh pr create/list/view/checkout/merge,gh issue create。

限制与注意:push 过的提交禁止 amend 或 reset(会改写历史);共享分支(如 main、develop)禁止 --force push,仅个人 feature 分支可强制推送;.env、.key、.pem、secrets/、node_modules/、dist/、.DS_Store 等应写入 .gitignore;误提交密钥需用 BFG 清理历史并立即废止、重发密钥;在当前目录即为目标仓库时不应使用 git -C 选项。资料未提供官方收费、价格与平台信息。