| name | git-history-cleaner |
| description | Cleans up git commit history by rebasing and combining commits that edit the same files or logical units, ensuring each logical change is isolated to a single commit. |
Git History Cleaner
This skill provides a procedural workflow and strategies for cleaning up git commit history. It details how to reorganize, reorder, and combine (squash or fixup) commits to achieve a clean history where each file, feature, or logical unit is introduced/modified in a single self-contained commit.
Workflow
-
Analyze Commit History:
- Identify the base commit (e.g.,
origin/main, master, or a specific hash where the branch diverged) and the current branch HEAD.
- View the commit messages in reverse chronological order:
git log <base>..HEAD --oneline
- List files modified in each commit:
git log <base>..HEAD --name-status
-
Group Changes by Logical Units:
- Map files to their logical units (e.g., a specific module, script, library, or config).
- Identify "fixup" commits (commits fixing errors or formatting in files that were introduced or modified in earlier commits on the branch).
- Plan the squashing order: each logical unit or file set should be introduced in a single commit, incorporating all subsequent fixes to those same files.
-
Rebase and Combine Commits:
-
Verify the Rebased History:
-
Update Branch Pointer: