commit-push

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Commit and Push

提交与推送

Commit all local changes following Conventional Commits format and push to remote.
遵循Conventional Commits格式提交所有本地变更并推送至远程仓库。

Step 1: Gather Context

步骤1:收集上下文

Run these commands in parallel to understand the changes:
bash
undefined
并行运行以下命令以了解变更情况:
bash
undefined

See all untracked and modified files

查看所有未跟踪和已修改的文件

git status
git status

See staged and unstaged changes

查看暂存和未暂存的变更

git diff git diff --cached
git diff git diff --cached

See recent commit messages for style reference

查看最近的提交信息以参考格式

git log --oneline -10
undefined
git log --oneline -10
undefined

Step 2: Analyze Changes

步骤2:分析变更

Review the changes and determine:
  • Type: What kind of change is this?
    • feat
      - New feature or capability
    • fix
      - Bug fix
    • docs
      - Documentation only
    • refactor
      - Code restructure without behavior change
    • test
      - Adding or updating tests
    • chore
      - Maintenance, dependency updates
    • perf
      - Performance improvement
    • ci
      - CI/CD changes
  • Scope: Which component is affected?
    • Examine the changed files and determine the appropriate scope
    • Use consistent scope names within the project (check
      git log
      for patterns)
    • (omit scope for cross-cutting changes)
  • Breaking: Does this break backward compatibility? If yes, add ! after scope.
审阅变更并确定:
  • 类型:这属于哪种类型的变更?
    • feat
      - 新功能或能力
    • fix
      - 修复Bug
    • docs
      - 仅文档变更
    • refactor
      - 代码重构,无行为变更
    • test
      - 添加或更新测试
    • chore
      - 维护工作、依赖更新
    • perf
      - 性能优化
    • ci
      - CI/CD相关变更
  • 范围:哪个组件受到影响?
    • 检查变更的文件,确定合适的范围
    • 在项目内使用一致的范围名称(可查看
      git log
      寻找模式)
    • (跨模块变更可省略范围)
  • 破坏性:是否破坏向后兼容性?如果是,在范围后添加**!**。

Step 3: Write Commit Message

步骤3:编写提交信息

Format:
type(scope): description

[optional body explaining why, not what]

[optional footer with issue references]
Rules:
  • Use imperative mood: "add feature" not "added feature"
  • Keep first line under 72 characters
  • Focus on why in the body, the diff shows what
  • Reference issues:
    Closes #123
    or
    Fixes #456
格式:
type(scope): description

[可选正文,解释原因而非内容]

[可选页脚,包含问题引用]
规则:
  • 使用祈使语气:"add feature" 而非 "added feature"
  • 第一行不超过72个字符
  • 正文聚焦于原因,diff会展示内容
  • 引用问题:
    Closes #123
    Fixes #456

Step 4: Stage, Commit, and Push

步骤4:暂存、提交与推送

bash
undefined
bash
undefined

Stage all changes (or selectively stage)

暂存所有变更(或选择性暂存)

git add -A
git add -A

Commit with message (use HEREDOC for multi-line)

使用多行信息提交(使用HEREDOC)

git commit -m "$(cat <<'EOF' type(scope): description
Optional body explaining the motivation.
Closes #123
Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com EOF )"
git commit -m "$(cat <<'EOF' type(scope): description
Optional body explaining the motivation.
Closes #123
Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com EOF )"

Push to remote

推送至远程仓库

git push
undefined
git push
undefined

Examples

示例

bash
undefined
bash
undefined

Simple feature

简单功能提交

git commit -m "feat(api): add pagination support to list endpoints"
git commit -m "feat(api): add pagination support to list endpoints"

Bug fix with body

带正文的Bug修复提交

git commit -m "$(cat <<'EOF' fix(auth): handle token expiration during long requests
The previous implementation did not account for tokens expiring during the processing of long-running requests.
Fixes #42
Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com EOF )"
git commit -m "$(cat <<'EOF' fix(auth): handle token expiration during long requests
The previous implementation did not account for tokens expiring during the processing of long-running requests.
Fixes #42
Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com EOF )"

Breaking change

破坏性变更提交

git commit -m "$(cat <<'EOF' feat!(api): change response format for user endpoints
BREAKING CHANGE: The
status
field is now an object with
state
and
message
properties instead of a plain string.
Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com EOF )"
undefined
git commit -m "$(cat <<'EOF' feat!(api): change response format for user endpoints
BREAKING CHANGE: The
status
field is now an object with
state
and
message
properties instead of a plain string.
Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com EOF )"
undefined

Step 5: Verify

步骤5:验证

After pushing, run
git status
to confirm the working tree is clean and the branch is up to date with remote.
推送完成后,运行
git status
确认工作树干净,且本地分支与远程分支保持同步。