Apply staged changes to a selected commit in history (rewrites history)
From arribanpx claudepluginhub nmoinvaz/speedy-gonzales --plugin arribaApply the currently staged changes to a commit by rewriting git history.
First verify there are staged changes with git diff --cached --stat
If no staged changes, give the option to stage all changes. If I chose to stage all the git modified files, run git add -A and continue. If not, stop.
Get the last 8 commits and the staged diff:
git log --oneline -8
git diff --cached --stat
Determine which staged files and lines are affected:
git diff --cached --name-only
git diff --cached --unified=0
Rank commits by how well they match the staged changes, preferring in this order:
git log -p or git blame)Present the ranked list to the user with a recommended commit and a brief reason for the recommendation.
Give the user the option to accept the recommendation or select a different commit
Once the user selects a commit, create a fixup commit:
git commit --fixup=<selected-hash>
Perform an interactive rebase with autosquash:
GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash <selected-hash>~1
Report success or any conflicts that need resolution
If there are rebase conflicts:
git rebase --continue, or abort with git rebase --abort