SuperAPI AI 工具集

modern-git

编程与开发

查看项目

更新于 10-15 20:31

技能介绍

用途:该技能用于指导 AI 智能体生成符合现代 Git 规范的命令,避免使用 git checkout 等语义混杂的旧命令,让代码意图更清晰、更安全。

主要能力与规则:分支操作使用 git switch(git switch main、git switch -c feature-branch、git switch - 返回上一分支)替代 git checkout。文件操作使用 git restore:git restore <file> 丢弃工作区改动,git restore --staged <file> 取消暂存,git restore --source=<commit> <file> 从指定提交恢复,git restore --staged --worktree <file> 同时取消暂存并丢弃。强制推送使用 git push --force-with-lease origin <branch> 替代 git push --force,避免覆盖他人提交。

典型用法示例:开启新功能时依次执行 git switch main、git pull、git switch -c feature/new-feature;rebase 后安全推送为 git rebase main 加 git push --force-with-lease origin feature-branch。建议先 git status、git diff 确认再丢弃改动,必要时用 git stash 保留可恢复点。

限制与例外:部分场景无现代等价命令,如探索历史(分离 HEAD)仍可用 git checkout <commit> 或更明确的 git switch --detach <commit>,复杂远程跟踪 git checkout -b local origin/remote 仍常见。规则是:有现代等价命令就使用现代命令。