Skip to content

Editing Commit Messages

Christopher edited this page Oct 1, 2025 · 1 revision

Renaming Commit Messages in Git

Sometimes you need to change a commit message, whether it’s the most recent one you haven’t pushed yet, or an older one already in history. This guide shows both approaches.

Side Note: If you want to attach Issues Number to a commit, you simply just need to write '#N' (N being the issues number) and github will automatically attach it for you. Ex:

feature: Added scafolding for simulator class. #26
image

1. Change the Last Commit Message (Not Pushed Yet)

If you haven’t pushed the commit yet, you can simply amend it:

git commit --amend -m "New commit message"
  • This replaces the last commit message.
  • If you want to edit in your default editor instead of inline, just run:
git commit --amend

2. Change Older Commit Messages (Already pushed)

1. Go find which commit.

Go to Github under your commits on the branch, and count how many commits in the past you can to change. Once you have your commit number (e.g. 4 commits ago) run:

git rebase -i HEAD~4

2. In the terminal you will see something like this:

pick a1b2c3d First commit
pick d4e5f6g Add feature
pick h7i8j9k Fix bug

With your arrow keys you can scroll to the commit message and place your cursor on it.

3. Go into Insert Mode.

Press i, and edit the 'pick' word to 'reword'

It should go from

pick a1b2c3d First commit

to

reword a1b2c3d First commit

4. Now Save and Close.

Write and Quit the editor by doing:

:wq + Enter 

Now you will see your commit message at the top of the terminal that you can modify, by clicking 'i' (Insert Mode).

5. Save and Quit Again

Write and Quit the editor by doing again:

:wq + Enter 

6. Push Changes

Make sure your branch is checked out on your vscode and run:

git push origin your-branch --force

Hopefully this helps :D

Clone this wiki locally