git-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Review - 本地代码审查

Git Review - Local Code Review

推送前的代码自检工具,输出专业审查报告。
Code self-inspection tool before pushing, outputs professional review reports.

Workflow

Workflow

1. 确定审查范围(自动选择)

1. Determine Review Scope (Auto-selection)

自动选择逻辑(按优先级):
  1. 检查是否有已提交未推送的变更 → 有则选择此范围
  2. 检查是否有已暂存未提交的变更 → 有则选择此范围
  3. 检查是否有未暂存的变更 → 有则选择此范围
  4. 无变更则提示用户
用户也可手动指定范围:
范围Git 命令场景
未暂存
git diff
检查工作区修改
已暂存未提交
git diff --cached
commit 前检查
已提交未推送
git diff origin/$(git branch --show-current)
push 前检查
Auto-selection logic (by priority):
  1. Check for committed but unpushed changes → Select this scope if exists
  2. Check for staged but uncommitted changes → Select this scope if exists
  3. Check for unstaged changes → Select this scope if exists
  4. Prompt user if no changes exist
Users can also manually specify the scope:
ScopeGit CommandScenario
Unstaged
git diff
Check workspace modifications
Staged but Uncommitted
git diff --cached
Check before commit
Committed but Unpushed
git diff origin/$(git branch --show-current)
Check before push

2. 确定审查风格(自动选择)

2. Determine Review Style (Auto-selection)

默认风格:professional(专业严谨)
用户也可手动指定:
  • professional: 专业严谨,使用标准工程术语
  • sarcastic: 讽刺风格,技术指正准确
  • gentle: 温和风格,多用"建议"、"可以考虑"
  • humorous: 幽默风格,适当使用 Emoji
Default style: professional (rigorous and professional)
Users can also manually specify:
  • professional: Rigorous and professional, uses standard engineering terminology
  • sarcastic: Sarcastic style, with accurate technical corrections
  • gentle: Gentle style, uses "suggestion", "may consider" frequently
  • humorous: Humorous style, uses appropriate Emojis

3. 获取变更内容

3. Obtain Change Content

bash
undefined
bash
undefined

获取 diff

Get diff

git diff <scope>
git diff <scope>

获取最近 commit 信息(作为上下文)

Get recent commit information (as context)

git log --oneline -5
undefined
git log --oneline -5
undefined

4. 执行审查

4. Execute Review

使用以下 System Prompt 进行审查:
你是一位资深的软件开发工程师,专注于代码的规范性、功能性、安全性和稳定性。
使用以下 System Prompt 进行审查:
You are a senior software development engineer, focusing on code standardization, functionality, security, and stability.

代码审查目标:

Code Review Objectives:

  1. 功能实现的正确性与健壮性(40分):确保代码逻辑正确,能够处理各种边界情况和异常输入。
  2. 安全性与潜在风险(30分):检查代码是否存在安全漏洞(如SQL注入、XSS攻击等),并评估其潜在风险。
  3. 是否符合最佳实践(20分):评估代码是否遵循行业最佳实践,包括代码结构、命名规范、注释清晰度等。
  4. 性能与资源利用效率(5分):分析代码的性能表现,评估是否存在资源浪费或性能瓶颈。
  5. Commits信息的清晰性与准确性(5分):检查提交信息是否清晰、准确,是否便于后续维护和协作。
  1. Correctness and robustness of function implementation (40 points): Ensure code logic is correct and can handle various boundary cases and abnormal inputs.
  2. Security and potential risks (30 points): Check if the code has security vulnerabilities (such as SQL injection, XSS attacks, etc.) and evaluate its potential risks.
  3. Compliance with best practices (20 points): Evaluate whether the code follows industry best practices, including code structure, naming conventions, comment clarity, etc.
  4. Performance and resource utilization efficiency (5 points): Analyze the performance of the code and evaluate whether there is resource waste or performance bottlenecks.
  5. Clarity and accuracy of commit information (5 points): Check if the commit information is clear and accurate, and whether it facilitates subsequent maintenance and collaboration.

输出格式:

Output Format:

请以Markdown格式输出代码审查报告,包含:
  1. 问题描述和优化建议(如果有):列出代码中存在的问题,简要说明其影响,并给出优化建议
  2. 评分明细:为每个评分标准提供具体分数
  3. 总分:格式为"总分:XX分"(例如:总分:80分),确保可通过正则表达式 r"总分[::]\s*(\d+)分?" 解析
Please output the code review report in Markdown format, including:
  1. Problem descriptions and optimization suggestions (if any): List the problems in the code, briefly explain their impacts, and provide optimization suggestions
  2. Score details: Provide specific scores for each scoring criterion
  3. Total score: Format as "Total Score: XX points" (e.g.: Total Score: 80 points), ensuring it can be parsed by the regular expression r"Total Score:\s*(\d+) points?"

特别说明:

Special Notes:

整个评论要保持 {style} 风格
undefined
The entire review should maintain the {style} style
undefined

5. 输出报告

5. Output Report

同时输出到两个位置:
  1. 对话中显示 - 直接在对话中输出审查结果
  2. 保存到文件 - 保存到
    docs/reviews/
    目录
文件命名格式:
docs/reviews/YYYY-MM-DD_HH-MM_branch-name_score.md
示例:
docs/reviews/2026-02-27_11-30_feature-login_85.md
文件内容模板:
markdown
undefined
Output to two locations simultaneously:
  1. Display in conversation - Directly output the review result in the conversation
  2. Save to file - Save to the
    docs/reviews/
    directory
File naming format:
docs/reviews/YYYY-MM-DD_HH-MM_branch-name_score.md
Example:
docs/reviews/2026-02-27_11-30_feature-login_85.md
File content template:
markdown
undefined

Code Review Report

Code Review Report

日期: 2026-02-27 11:30 分支: feature-login 审查范围: 已提交未推送 审查人: AI Code Reviewer

Date: 2026-02-27 11:30 Branch: feature-login Review Scope: Committed but Unpushed Reviewer: AI Code Reviewer

📋 审查摘要

📋 Review Summary

...
...

🔍 问题与建议

🔍 Issues and Suggestions

...
...

📊 评分明细

📊 Score Details

  • 功能正确性与健壮性:35/40
  • 安全性与潜在风险:25/30
  • 最佳实践:18/20
  • 性能与资源利用:4/5
  • Commits信息清晰性:3/5
总分:85分

  • Correctness and robustness of function implementation: 35/40
  • Security and potential risks: 25/30
  • Best practices: 18/20
  • Performance and resource utilization: 4/5
  • Clarity of commit information: 3/5
Total Score: 85 points

审查的代码变更

Reviewed Code Changes

<details> <summary>点击查看 diff</summary>
diff
... diff 内容 ...
</details> ```
<details> <summary>Click to view diff</summary>
diff
... diff content ...
</details> ```

Review Criteria

Review Criteria

详见 references/review-criteria.md
See references/review-criteria.md.

Notes

Notes

  • diff 内容过长(>10000 tokens)时截取前 10000 tokens
  • 配置文件、lock 文件等自动生成的变更可跳过
  • 评分客观公正,扣分需给出具体理由
  • 问题定位到具体文件和行号
  • Truncate to the first 10000 tokens when diff content is too long (>10000 tokens)
  • Skip automatically generated changes such as configuration files and lock files
  • Scoring should be objective and fair, specific reasons are required for deducting points
  • Locate problems to specific files and line numbers