git-amend
Amend commit ล่าสุดอย่างปลอดภัย — เช็ค pushed ก่อน, staged changes และ message edit
SKILL.mdgit-amend/SKILL.md
GitHubGoal
Fix the latest commit with git commit --amend — add changes or edit the message — without rewriting pushed history
Scope
- amend staged changes into the latest commit, edit the commit message,
--no-edit - covers only the HEAD commit — to fix older commits →
/git-rebase(autosquash)
Execute
1. Safety Check
Goal: Confirm the amend does not rewrite public history
git status— has the latest commit been pushed already (git statusshows ahead/behind, orgit log origin/<branch>..HEAD)- already pushed → never amend — create a new commit, or
/git-revertif it must be undone - if others may have pulled this branch already → do not amend either
2. Stage And Amend
Goal: the changed content/message is merged into the original commit
git add <files>
git commit --amend --no-edit # add changes without editing the message
git commit --amend -m "new msg" # edit the message
git commit --amend # edit both (opens editor)
- stage only the changes that belong to that commit — amend includes all staged content
- amend changes the sha — commits that depend on the old sha (cherry-picks, notes) keep stale references
3. Verify
Goal: the commit is correct and history stays clean
git show HEAD— content + message match the intentgit log --oneline -3— no duplicate/broken commits- if the branch is already pushed and amend is required (e.g. a local-only branch pushed as preview) →
git push --force-with-leaseonly
Rules
- amend only commits that have not been pushed — pushed = rewriting public history
--force-with-leaseonly if pushing is required after amend — never--force- do not amend to fix a change that should be a new commit — amend corrects the existing commit, it is not a way to avoid new history
- amending while a rebase/merge is in progress → resolve that state first
- Use /ask-me if needed
Expected Outcome
- the HEAD commit has the correct changes/message with a new sha
- no shared history was rewritten