Git rewrite
Rewrite git history by modifying existing commits via interactive rebase. Use this skill whenever the user wants to edit, fix, or clean up past commits — for example removing lines from old commits, splitting commits, rewriting commit messages across multiple commits, or making surgical changes to specific commits in history. Triggers on phrases like "rebase", "edit commit", "fix that commit", "clean up history", "remove from old commit", "amend past commit", or any request that implies changing commits that aren't HEAD.From its SKILL.md
npx -y skills add Hogeyama/agent-skills --skill git-rewriteAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.2 KB, as published. Nobody here has run it
Git History Rewrite via git rebase -i
GIT_SEQUENCE_EDITOR + sed -E パターン
git rebase -i のtodoリストは rebase.abbreviateCommands 設定次第で pick または p になる。
必ず sed -E で ^(p|pick) を使い、両方にマッチさせること。
# edit (内容変更): 停止 → 修正 → git commit --amend --no-edit → git rebase --continue
GIT_SEQUENCE_EDITOR="sed -i -E \
-e 's/^(p|pick) (<hash1>)/edit \2/' \
-e 's/^(p|pick) (<hash2>)/edit \2/'" \
git rebase -i <base>
# reword (メッセージ変更のみ)
GIT_SEQUENCE_EDITOR="sed -i -E 's/^(p|pick) (<hash>)/reword \2/'" git rebase -i <base>
# drop (コミット削除)
GIT_SEQUENCE_EDITOR="sed -i -E 's/^(p|pick) (<hash>)/drop \2/'" git rebase -i <base>
完了後: git range-diff の表示
リベースが成功したら、必ず git range-diff で旧コミットと新コミットの差分をユーザーに提示する。
リベース開始前に旧 HEAD のコミットハッシュを変数等で控えておき、完了後に以下のように比較する。
# リベース開始前
OLD_HEAD=$(git rev-parse HEAD)
# ... リベース実行 ...
# リベース完了後
git --no-pager range-diff <base>..$OLD_HEAD <base>..HEAD
<base>はリベースの起点コミット(git rebase -i <base>で指定したもの)。$OLD_HEADはリベース開始前に控えた旧 HEAD。- これにより各コミットごとに何が変わったかが一目でわかる。
Stale rebase の掃除
"rebase-merge directory" エラーが出たら:
git rebase --abort 2>/dev/null; rm -fr .git/rebase-merge 2>/dev/null