一键导入
git-smart-fixup
Split staged changes or HEAD commit into `fixup!` commits that target the appropriate previous commits in the current branch.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Split staged changes or HEAD commit into `fixup!` commits that target the appropriate previous commits in the current branch.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | git-smart-fixup |
| description | Split staged changes or HEAD commit into `fixup!` commits that target the appropriate previous commits in the current branch. |
User invokes /smart-fixup or asks to split changes into fixup commits.
--from-head: Use the HEAD commit instead of staged changes (will reset HEAD and recreate as fixups)--dry-run: Show what fixup commits would be created without actually creating them--base <ref>: Specify the base branch (default: auto-detect master/main)Find the merge base between current branch and main/master:
git merge-base HEAD master
Get the list of commits from merge base to HEAD (these are candidates for fixup targets):
git log --oneline --reverse <merge-base>..HEAD
Store commit hashes and their messages for later matching.
If using staged changes (default):
git diff --cached --unified=0
If using --from-head:
# Get the diff from HEAD commit
git show HEAD --unified=0 --format=""
# Store HEAD message for potential fallback
git log -1 --format="%s" HEAD
# Soft reset to unstage HEAD's changes
git reset --soft HEAD~1
For each changed file and hunk:
Parse the diff to extract file paths and line ranges.
For each modified/deleted line range, use git blame to find which commit last touched those lines:
# For the version before our changes, blame the lines being modified
git blame -l -L <start>,<end> <merge-base>..HEAD~1 -- <file> 2>/dev/null
If blaming the range fails (new lines), check the surrounding context:
git blame -l -L <start-3>,<start> HEAD~1 -- <file> 2>/dev/null
For each hunk, determine the target commit:
Create a mapping of target commits to their associated hunks:
{
"<commit-hash-1>": [hunk1, hunk2, ...],
"<commit-hash-2>": [hunk3, ...],
"NEW": [hunk4, hunk5, ...] // Changes not attributable to any branch commit
}
For each target commit with associated hunks:
Stage only the relevant hunks using git add -p or by creating patch files:
# Create a patch for this group of hunks
# Apply with: git apply --cached <patch-file>
Create the fixup commit:
git commit --fixup=<target-commit-hash>
For changes marked as "NEW" (not attributable to branch commits):
--from-head was used, use the original HEAD commit messageDisplay a summary:
Original commit: <original-head>
Created X fixup commits:
fixup! <original-commit-message-1> (N files, M lines)
fixup! <original-commit-message-2> (N files, M lines)
Remaining changes (not matched to branch commits):
<new-commit-message> (N files, M lines)
To confirm that these commits match the original state, run:
git diff <original-head>..<new-head>
To squash these fixups, run:
git rebase -i --autosquash <merge-base>
No staged changes and no --from-head: Error with helpful message.
New files: These typically become a new commit unless the user added them alongside modifications to existing code.
Binary files: Skip blame analysis, treat as new changes.
Renamed files: Use git log --follow to track through renames.
git diff --cached -U0 for minimal context when parsing hunks@@ -start,count +start,count @@git log -S or git log -G as fallback for finding related commits