Rewrites, squashes, and reorganizes git commit history to create clean, reviewable branches. Covers git-native rebase patterns and GitButler equivalents.
Ships in preferences-code-and-collaboration-conventions. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This skill covers history refinement in git-native and GitButler modes (git rebase -i, git revise, but move/but squash/but reword, GIT_SEQUENCE_EDITOR patterns).
For jj-mode history refinement (jj rebase, jj squash, jj split, jj abandon, jj describe -r), see jj-history-cleanup.
In a jj-colocated repository, do not apply any git rebase -i or git revise recipe from this file to the working copy; jj history refinement and the @-stays-empty-[wip] development-join invariant are owned by jj-history-cleanup and the jj-version-control skill's diamond-workflow.md.
Mode detection is described in preferences-git-version-control §"Commit behavior override".
Transform experimental development history into a clean, reviewable commit sequence where:
This prepares branches for PR review by creating a clear narrative of what changed and why.
When gitbutler/workspace is checked out, the but CLI provides native history editing commands that replace git rebase -i.
The git-rebase patterns in the rest of this skill apply only to git-native mode.
| Git operation | but equivalent |
|---|---|
git rebase -i (reorder) | but move <commit> <target-commit> (within branch) or but move <commit> <branch> (cross-stack) |
git rebase -i (squash) | but squash <source-commit> <target-commit> |
git rebase -i (reword) | but reword <commit> -m "new message" |
git rebase -i (edit) | but uncommit <commit> then re-commit with changes |
git commit --amend | but amend <file-id> <commit-id> |
git revise | Same but commands above --- but subsumes git revise functionality |
git rebase --abort | but undo (reverts last operation) |
All but mutation commands accept --status-after to display the updated workspace state.
Always use fresh CLI IDs from but status -fv before each operation, as IDs change after every mutation.
The git-native patterns below (interactive rebase, GIT_SEQUENCE_EDITOR, git revise) remain the correct approach when working in repositories not managed by GitButler.
Never trigger interactive editors. All operations use GIT_SEQUENCE_EDITOR and GIT_EDITOR environment variables with non-interactive commands.
GIT_SEQUENCE_EDITOR="command-to-edit-todo" git rebase -i <base>
The rebase todo file has one line per commit: <action> <hash> <message>
Use sed/awk to rearrange lines in the todo file:
# Move commit at line N to line M (example: move line 3 to line 1)
GIT_SEQUENCE_EDITOR="awk 'NR==3 {saved=\$0; next} NR==1 {print saved} {print}' > /tmp/rebase-todo && cat /tmp/rebase-todo" git rebase -i HEAD~5
# Reverse order
GIT_SEQUENCE_EDITOR="tac" git rebase -i HEAD~3
# Custom order: use awk to print lines in desired sequence
GIT_SEQUENCE_EDITOR="awk '{lines[NR]=\$0} END {for (i in order) print lines[order[i]]}'" git rebase -i HEAD~N
# Squash commit at line N into previous (N-1)
GIT_SEQUENCE_EDITOR="sed -i.bak 'Ns/^pick/squash/'" git rebase -i HEAD~5
# Fixup (squash without message)
GIT_SEQUENCE_EDITOR="sed -i.bak 'Ns/^pick/fixup/'" git rebase -i HEAD~5
# Squash all commits after first
GIT_SEQUENCE_EDITOR="sed -i.bak '2,\$s/^pick/squash/'" git rebase -i HEAD~5
# Drop commit at line N
GIT_SEQUENCE_EDITOR="sed -i.bak 'Nd'" git rebase -i HEAD~5
# Drop by marking as 'drop'
GIT_SEQUENCE_EDITOR="sed -i.bak 'Ns/^pick/drop/'" git rebase -i HEAD~5
# Mark for reword, then use GIT_EDITOR to set message
GIT_SEQUENCE_EDITOR="sed -i.bak 'Ns/^pick/reword/'" \
GIT_EDITOR="echo 'new message' >" \
git rebase -i HEAD~5
# For multiple rewords, use a script that checks commit hash
# Mark commit for edit at line N
GIT_SEQUENCE_EDITOR="sed -i.bak 'Ns/^pick/edit/'" git rebase -i HEAD~5
# Rebase will pause; make changes, then:
git add <files>
git commit --amend --no-edit
git rebase --continue
# Mark for edit
GIT_SEQUENCE_EDITOR="sed -i.bak 'Ns/^pick/edit/'" git rebase -i HEAD~5
# When paused:
git reset HEAD^
git add <files-for-first-commit>
git commit -m "first part"
git add <files-for-second-commit>
git commit -m "second part"
git rebase --continue
#!/bin/bash
# reorder-script.sh
# Reads git-rebase-todo from $1, writes modified version back
awk '{lines[NR]=$0} END {
# Print in desired order
print lines[3]
print lines[1]
print lines[2]
}' "$1" > "$1.tmp" && mv "$1.tmp" "$1"
chmod +x reorder-script.sh
GIT_SEQUENCE_EDITOR="./reorder-script.sh" git rebase -i HEAD~3
For complex history rewrites:
Run separate rebase operations rather than one complex edit.
# If rebase conflicts:
git status # identify conflicts
# Fix conflicts manually
git add <resolved-files>
git rebase --continue
# To abort:
git rebase --abort
Clean up 5 commits: reorder, squash 2 & 3, drop 4, reword 5
# Step 1: Create reorder script
cat > /tmp/rebase-edit.sh << 'EOF'
#!/bin/bash
awk '{lines[NR]=$0} END {
print lines[1]
gsub(/^pick/, "squash", lines[3])
print lines[3]
gsub(/^pick/, "drop", lines[4])
print lines[4]
gsub(/^pick/, "reword", lines[5])
print lines[5]
print lines[2]
}' "$1" > "$1.tmp" && mv "$1.tmp" "$1"
EOF
chmod +x /tmp/rebase-edit.sh
# Step 2: Run rebase
GIT_SEQUENCE_EDITOR="/tmp/rebase-edit.sh" \
GIT_EDITOR="echo 'New message for commit 5' >" \
git rebase -i HEAD~5
After any history rewrite:
git log --oneline --graph -n 10
git diff <original-branch>..HEAD # Should be empty for pure history changes
git revise is faster than git rebase (in-memory, doesn't touch working directory) and well-suited for linear history cleanup.
drop command: all commits must be accounted for (use fixup to absorb unwanted commits)<action> <hash> <message> (simpler than rebase)git revise -m <target> -m "new message" (no editor needed)git reset @{1} (single reflog entry)# Reword a specific commit without interactive mode
git revise --no-gpg-sign <target-hash> -m "new commit message"
# Apply fixups using GIT_SEQUENCE_EDITOR (same as rebase)
cat > /tmp/revise-editor.sh << 'SCRIPT'
#!/bin/bash
cat > "$1" << 'TODO'
pick <hash1> first commit message
fixup <hash2> fixup for first
pick <hash3> second commit message
fixup <hash4> fixup for second
TODO
SCRIPT
chmod +x /tmp/revise-editor.sh
GIT_SEQUENCE_EDITOR="/tmp/revise-editor.sh" git revise -i --no-gpg-sign <base>^
Complex rewrites are safer as separate operations:
git revise -m <hash> -m "message"git log --oneline, git show --stat <hash> for each commitWhen commit.gpgSign is configured but key unavailable, use --no-gpg-sign:
git revise --no-gpg-sign -i <base>
git revise --no-gpg-sign <hash> -m "message"
Fixup commits must immediately follow their target:
# Correct: fixup follows its target
pick abc123 feature implementation
fixup def456 fix typo in feature
# Wrong: fixup before target (will squash into wrong commit)
fixup def456 fix typo in feature
pick abc123 feature implementation
When a commit removes something and a later commit restores it (net effect: just comments/modifications), squash them:
# Before: A removes X, B restores X with comment, C fixes comment
# After: single commit with just the comment
cat > /tmp/revise-editor.sh << 'SCRIPT'
cat > "$1" << 'TODO'
pick <hash-A> remove X
fixup <hash-B> restore X with comment
fixup <hash-C> fix comment
TODO
SCRIPT
GIT_SEQUENCE_EDITOR="/tmp/revise-editor.sh" git revise -i --no-gpg-sign <hash-A>^
# Then reword with correct message
git revise --no-gpg-sign <new-hash> -m "add comment explaining X"
| Scenario | Tool | Reason |
|---|---|---|
| Simple linear cleanup | git revise | Faster, in-memory |
| Reword single commit | git revise -m | No editor needed |
| Complex reordering | git rebase -i | More flexible |
| Conflicts expected | git rebase -i | Better conflict UX |
| exec/break needed | git rebase -i | revise lacks these |
-i.bak with sed for safety (creates backup)git rebase --abort or git reset @{1} is available if things go wronggit rebase -i or git revise -i without GIT_SEQUENCE_EDITOR set--no-gpg-sign when GPG key is unavailableWhat SKILL.md sets; muted values are Claude Code's defaults
8 skills in this plugin
/preferences-change-managementChange management practices for controlled evolution of systems and codebases. Load when planning migrations, deprecations, or breaking changes./preferences-comment-cleanupUncomment-driven workflow for auditing and removing noise comments while preserving load-bearing markers, as the operational arm of the code-comments policy. Load when you remove comments, strip comments, uncomment or declutter code, run a comment cleanup, or systematically prune noise comments across a subtree./preferences-documentation/preferences-code-and-collaboration-conventions:preferences-git-history-cleanupfrom preferences-code-and-collaboration-conventions
npx claudepluginhub cameronraysmith/vanixiets --plugin preferences-code-and-collaboration-conventionsOther plugins' skills for the same job