What command allows you to rewrite commit messages for multiple commits?
Posted by SamPetr
Last Updated: July 20, 2024
To rewrite commit messages for multiple commits in Git, you can use the git rebase command with the -i (interactive) option. Here’s how you can do it: 1. Open your terminal. 2. Navigate to your Git repository. 3. Use the following command to start an interactive rebase for the last N commits (replace N with the number of commits you want to rewrite):
git rebase -i HEAD~N
4. This will open your default text editor with a list of the last N commits. Each commit will be prefixed with the word pick. 5. Change pick to reword (or just r) for each commit whose message you want to edit. 6. Save and close the editor. 7. Git will then prompt you to enter a new commit message for each commit you've marked for rewording. 8. After you’ve updated the commit messages, save and close the editor again. This will rewrite the commit messages for the specified commits while maintaining their changes in the repository. Be cautious when rebasing and rewriting commit history, especially if you've already shared the commits with others, as this can cause complications in collaborative workflows.