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 adddo 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 addgit add -Agit add .git add <path>git commit -agit commit --allgit commit <pathspec>git update-indexand 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
git status --shortto check for staged, unstaged, and untracked changesgit diff --cached --name-statusorgit diff --cached --statto check only the staged changes- If there are no staged changes, abort at that point
- The commit message is
git diff --cachedonly from the contents of - 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) - When committing, do not add a pathspec or
--all, and do not usegit commit -F <path>do - 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 adddo not git commitWhen executing, commit only the staged index