Reword : Change Commit Messages of existing Commits
A beginner's guide to changing commit messages using rebase
What's Reword in git
Reword is a handy feature of git rebase that can be used to change commit messages, mostly used by me to fix typos and improve message clarity such that clean and concise commit messages exist in the repository. There are other ways to change commit messages as well.
When to use git reword?
Reword is particularly handy when you have to improve / change the commit messages of commits which have already been pushed to GitHub.
For changing last local commit message,
git commit --amend
can be handy to change the most recent commit message.
How to change messages using reword with interactive rebase.
For using interactive rebasing to change the commit messages, we will need the commit id, or a simple method is to use
git rebase -i HEAD~n
n = Number of commits to display from the latest commit.
This will open a file in the code editor or terminal that looks somewhat like this.
In this file, replace, pick
with reword
for the commits where the message needs to be changed.
Save and close the file. This will open another file in which the commit message for the commit can be changed.
Just change the commit message in this file.
After making the required changes to the commit message, save and close the file. A message like this should appear
Changed the commit message
Push the changes to the using --force
.
Final Conclusion
The reword feature within Git rebase emerges as a valuable asset for refining commit messages even after they have been pushed to GitHub. Developers can make sure that their commit history upholds a high standard of precision and clarity by utilising this tool.