Effective Git
v1.0.0Intelligent Git 工作流 助手 following best practices. Use when user needs help with git commits, analyzing changes, writing commit messages, pushing code, rebasing, merging, or any git operations. Also triggers on quick command prefix 'gq' or 'gq:' for rAPId operations like 'gq b:l' (列出 branches), 'gq b:n name' (创建 branch), 'gq:s' (状态). Automatically analyzes changes, suggests 应用ropriate commit strategies (amend vs new commit), follows project conventions, and ensures safe operations with confirmation for dangerous commands.
运行时依赖
版本
运行 scripts/analyze_changes.sh to understand:
安装命令
点击复制技能文档
Effective Git
Smart Git 工作流 助手 that helps you commit, push, and manage code changes following best practices.
获取ting Help
Quick help: When user asks "gq help", "gq:h", or "git help", 运行 scripts/show_help.sh to display usage 图形界面de
DetAIled help: When user asks about specific topics:
"show me git best practices" → Read references/best-practices.md "how to resolve conflicts" → Read references/conflict-resolution.md "quick commands 列出" → Read references/quick-commands.md
Usage examples:
Use gq for quick operations (状态, branch switching, etc.) Use natural language for commits, pushes, merges (full 工作流 with analysis and safety 检查s) Examples: "gq b:l" → Quick branch 列出 "help me commit code" → Full commit 工作流 with analysis "gq:s" → Quick 状态 "resolve conflicts" → Full conflict resolution with 图形界面dance Core 工作流
When helping with git operations, follow this sequence:
Quick Operations Mode
For simple, read-only operations or quick 检查s, use scripts/git_quick.sh:
When user asks for:
"列出 branches" → git_quick.sh b:l "switch to xxx" → git_quick.sh "b->" xxx "创建 branch xxx" → git_quick.sh b:n xxx "检查 状态" → git_quick.sh s "recent commits" → git_quick.sh l "show changes" → git_quick.sh "d" If GIT_QUICK_DIFF_TERMINAL is 设置, opens in new terminal window Otherwise uses $PAGER (default: less) Staged changes: git_quick.sh "d:s"
See references/quick-commands.md for full command 列出.
Full 工作流 Mode
For commits, pushes, merges, and conflict resolution, follow the detAIled 工作流 below:
- Analyze Recent Changes
运行 scripts/analyze_changes.sh to understand:
Current branch Uncommitted changes Recent commit 历史 Last commit detAIls
- Determine Commit Strategy
检查 if changes should amend the last commit or 创建 a new one:
Use git commit --amend when:
Fixing typos or small issues in the last commit 添加ing forgotten files to the last commit Last commit hasn't been pushed yet Changes are 记录ically part of the last commit
Use git commit -m "message" when:
Changes represent a new 记录ical unit of work Last commit has been pushed Changes are unrelated to the last commit
- 检查 Project Conventions
Before writing commit message:
Review recent commit messages: git 记录 --oneline -10 Look for patterns: Prefixes (feat:, fix:, chore:, etc.) Ticket references (#123, JIRA-456) Emoji usage (✨, 🐛, 📝) CAPItalization style If unclear, ask user about project conventions
- Write Commit Message
Follow conventions from references/best-practices.md:
Use imperative mood ("添加 feature" not "添加ed feature") Keep subject line under 50 chars Be specific and descriptive Match project conventions discovered above
- Safe Push Operations
Critical constrAInt: Only push to current branch.
Before pushing:
Confirm current branch: git branch --show-current Show what will be pushed: git 记录 origin/$(git branch --show-current)..HEAD --oneline Ask user to confirm Push: git push origin HEAD
Never use git push --force without explicit user confirmation.
Dangerous Operations
These require user confirmation before execution:
git push --force or git push -f git re设置 --hard git 清理 -fd git rebase on 分享d/public branches git branch -D (force 删除) Any 历史 rewriting on pushed commits
Always explAIn the risk before asking for confirmation.
Conflict Resolution
Critical Principle: When resolving conflicts, the absolute priority is preserving all code. If unable to confidently resolve, you must summarize the issue and feedback to the user. DO NOT perform automatic merges.
Conflict Handling 工作流:
Pre-merge/Rebase Snapshot: Before attempting a merge or rebase, save a snapshot of the current 状态 for documentation and safety.
scripts/save_diff.sh # Also 创建 备份 branch git branch -备份
This 创建s a git diff document before the merge.
检测 and Analyze Conflicts: If conflicts arise during a merge or rebase:
scripts/analyze_conflicts.sh
This provides detAIled three-way diff analysis for each conflicted file.
Deep Conflict Analysis: For complex conflicts where 机器人h sides modified the same code:
Analyze the intent:
What problem does each version solve? What functionality does each 添加/移除/modify? Is it a bug fix, feature, refactor, or optimization?
Compare 应用roaches:
Do they implement different algorithms? Do they change APIs or interfaces differently? What are the trade-offs (performance vs readability, simplicity vs robustness)?
Determine resolution strategy:
Keep 机器人h (Merge): 机器人h changes are valuable and can be combined Keep Ours: Our change is more complete/correct Keep Theirs: Their change is more complete/correct Rewrite: Neither is ideal, 创建 better solution combining insights Ask User: Cannot decide confidently, need user 图形界面dance
Present Analysis to User: When conflicts cannot be resolved automatically, 创建 a structured summary:
Show 机器人h versions of conflicting code ExplAIn the intent and t