SuperAPI AI Directory

kf-g-git-commit-staged-only-rules

General & other

View repository

Updated 10-15 20:24

About this skill

Git Commit staged-only convention

This skill is a convention for limiting the commit target to only staged changes when a commit is requested. When creating a commit message, use it together with kf-g-git-commit-japanese-commit-message .

Basic policy

  • The commit target is only the changes that are already staged at the time of the request
  • Do not include unstaged changes, untracked files, or unstaged deletions in the commit target
  • In the flow of a commit request, do not arbitrarily git add do not
  • If there are no staged changes at all, prompt the user to stage and abort

Prohibited actions

For commit requests, the following operations are strictly prohibited.

  • git add
  • git add -A
  • git add .
  • git add <path>
  • git commit -a
  • git commit --all
  • git commit <pathspec>
  • git update-index and other operations that directly modify the index
  • Implicit staging for reasons such as formatters, generators, or hook fixes

Even if the user explicitly states that staging is also necessary, do not stage arbitrarily in the same flow as the commit. First confirm what to stage, and separately confirm whether it is okay to proceed to commit after staging.

Confirmation procedure

  1. git status --short to check for staged, unstaged, and untracked changes
  2. git diff --cached --name-status or git diff --cached --stat to check only the staged changes
  3. If there are no staged changes, abort at that point
  4. The commit message is git diff --cached only from the contents of
  5. Write the commit message to a temporary file outside the repository (e.g., /tmp/commit-msg.txt), and pass it withgit commit -F <path> . Do not use heredoc (<<)、$()、backtick、-F - (while hooks can statically read the message file, the former involves expansion and external execution, making safety and lint targets harder to determine)
  6. When committing, do not add a pathspec or --all , and do not use git commit -F <path> do
  7. In the post-commit report, state as necessary that the commit target was only staged changes

When there are no staged changes

If there are no staged changes at all, do not commit. Do not substitute with an empty commit. Briefly tell the user to stage the target files and then request again.

Example:

stage 済み変更なし。commit 対象なし。
必要なファイルを `git add <path>` で stage してから再依頼して。

When there are unstaged changes

Even if there are unstaged changes or untracked files, do not include them in the commit target. Do not stage them arbitrarily, and if necessary, only report that unstaged changes are excluded from the commit.

The commit message's 概要 と Why Also write based only on staged changes. This is because mixing in the contents of unstaged changes causes the actual commit and the message to diverge.

Combined use with the commit message skill

kf-g-git-commit-japanese-commit-message Even when using it, the constraints of this skill take precedence.

  • Checking the most recent commit is allowed
  • Checking the staged diff is allowed
  • Do not use unstaged diffs as the basis for the commit message
  • Even after creating the commit message, git add do not
  • git commit When executing, commit only the staged index