I’ve had some people approach me after adding a git hook I made saying, now that I have the hook in place, how do I fix all my previous commits to use it?!
Once again, I offer some good news! It is possible and easy to run the git hook on your previous commits using Interactive Rebase.
Here is how you fix up all your previous commits to run the pre-commit hook you just added:
- Select commit prior to commits you want to run the hook on.
- Right-click > Rebase current branch on > Select Commit Hash
- Click Show options
- Check Interactive Rebase
- Press Rebase
- Your choosen Text Editor should open with git-rebase-todo window
- Add
exec git commit --amend -C HEAD
after each commit - Close the edit window
- Watch git do it’s work!