Reword
Overview
The reword command will enable you to edit a commit message without changing the commit content itself.
This is especially useful to fix a typo, clarify the scope of a commit or any other change before sharing into a pull request.
Setup playground
To practice you will create a playground repository and change few commits to follow Conventional Commit specification.
Conventional Commit
The Conventional Commit is a formalized pattern to write commit in a predictable way.
First, prepare you playground repository.
From the course repository root, run the command:
./scripts/create-playground.sh rebase-int_rewordThis will create the repository. Go to the folder and check the history.
cd playgrounds/rebase-int_reword ; git log --online2f4f83f (HEAD -> main) fix computation
9306b1d add debug
405fbdb implement Fibonacci computation
79c3575 debug array print
aaec7f3 implement the print of list
3e223a7 draft for main class and internal APIWARNING
As playground rebuild a new repository each time you create one, the SHA1 in this course are only example. Only consider those in your local repository as reference.
Activity goal
During this exercise, you will practice the use of "reword" rebase action.
This is a useful action that enables you to edit a commit message without changing the content of the commit itself.
A must-use action if you ever need to fix a typo or improve a commit description before delivering your code to peer review.
As you saw in the commit log, commit messages are not very much aligned with the Conventional Commit guidelines, so let's fix at least one of them.
Fixing a commit message
The very first step is obviously to start the interactive rebase:
git rebase -i --rootTIP
You must have noted that on this specific command I've not provided any commit.
Instead I use the --root option.
This instruct Git to start an interactive rebase for the very first commit in this repository.
Now the shell is waiting for your editor to close the rebase script, and your editor should show the interactive rebase script similar to the the one bellow (I only removed the comment lines):
pick 3e223a7 # draft for main class and internal API
pick aaec7f3 # implement the print of list
pick 79c3575 # debug array print
pick 405fbdb # implement Fibonacci computation
pick 9306b1d # add debug
pick 2f4f83f # fix computationReplace "pick" with "r" (reword abbreviation) for two commits:
- "implement the print of list"
- "fix computation"
You should have something like:
pick 3e223a7 # draft for main class and internal API
r aaec7f3 # implement the print of list
pick 79c3575 # debug array print
pick 405fbdb # implement Fibonacci computation
pick 9306b1d # add debug
r 2f4f83f # fix computationYou can save and close the editor.
And now the editor should open a "COMMIT_EDITING" for the first commit to edit:
implement the print of list
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Sun Nov 2 19:32:52 2025 +0100
#
# interactive rebase in progress; onto 33376ea
# Last commands done (2 commands done):
# pick 3e223a7 # draft for main class and internal API
# reword aaec7f3 # implement the print of list
# Next commands to do (4 remaining commands):
# pick 79c3575 # debug array print
# pick 405fbdb # implement Fibonacci computation
# You are currently editing a commit while rebasing branch 'main' on '33376ea'.
#
# Changes to be committed:
# modified: Main.java
#Change the commit first line to be:
feat: print a list of numbersSave and close the editor.
Check your shell, it should display how the rebase is going:
[detached HEAD 08665b8] feat: print a list of numbers
Date: Sun Nov 2 19:32:52 2025 +0100
1 file changed, 11 insertions(+), 1 deletion(-)
hint: Waiting for your editor to close the file...And a new "COMMIT_EDITING" file is now opened in your editor (I just removed the comment lines):
fix computationChange the commit to:
fix: computation issueSave and close again the editor and check your shell. You should see that interactive rebase completed properly:
[detached HEAD 08665b8] feat: print a list of numbers
Date: Sun Nov 2 19:32:52 2025 +0100
1 file changed, 11 insertions(+), 1 deletion(-)
[detached HEAD 1094f1b] fix: computation issue
Date: Sun Nov 2 19:42:17 2025 +0100
1 file changed, 1 insertion(+), 1 deletion(-)
Successfully rebased and updated refs/heads/main.And if you check the history, you should see the edited commits:
git log --oneline1094f1b (HEAD -> main) fix: computation issue
fffe266 add debug
c58f56f implement Fibonacci computation
21c8dc2 debug array print
08665b8 feat: print a list of numbers
3e223a7 draft for main class and internal APIBy checkin the output you can see:
- new commit message have replaced old ones;
- all commit hashes (SHA1) has been updated.
What we learned
You can edit a commit message older that your last commit!
Amending last commit is not the only way to improve commit message. An interactive rebase is a more flexible solution.
You have no more excuse to push crappy or obscure commit messages.