Sitemap

How to Edit Your Git Commit Messages with rebase -i

2 min readJun 15, 2025

--

Sometimes, when we’re using Git, we realize we made a commit message that isn’t quite clear, has typos, or simply doesn’t follow our naming style. For example:

bad message: Commit to rename

Suppose we meant it to be:

chore: Rename files and update references

We can change the message without creating a new commit, by using git rebase -i.

🔹But first… What does rebase -i do?

git rebase -i (or interactive rebase) lets you rewrite your branch's history in an interactive way.
This means you can:

✅ Change commit messages
✅ Reorder commits
✅ Combine (squash) multiple commits into a single one
✅ Remove unwanted commits

It’s a powerful tool to make your commit history clearer and more consistent before sharing it with your team.

Steps

✅ First, we can run:

git log --oneline

This lets us see a condensed view of our commits, along with their IDs:

abc123 (HEAD -> develop) bad message: Commit to rename
def456 feat: Implement pagination
ghi789 fix: Handle null cases gracefully
...

✅ Once we know which commit we want to change (say it’s abc123), we can execute:

git rebase -i "abc123^"

The abc123^ means “the parent of abc123.”
So we’re telling Git: "Start the rebase just before this commit."

✅ An editor will open with something like:

pick abc123 bad message: Commit to rename
...

✅ Here we simply change pick to reword:

reword abc123 bad message: Commit to rename

✅ Save and close the editor.
Now Git will pause at this commit and allow us to edit the message.
Your editor will show:

bad message: Commit to rename

Change it to:

chore: Rename files and update references

Save, close…
And you’re done!
Your commit now has a new message while keeping the rest of the history unaffected.

Final Notes

This procedure is especially useful when you’re working on a private branch or commits you haven’t pushed yet.
But watch out ⚡:
If you’re already working in a team and this commit has been pushed, you’ll need to force push:

git push origin branch-name --force

Use push --force with caution, and only when you’re sure it’s necessary, to avoid causing issues for teammates.

✅ That’s it!
Now you know how to adjust your Git messages without losing the history of your branch.

🚀 Tip:
This trick is handy for a single commit or for multiple messages in your Git history.
It’s a great way to keep your repository’s history clear, consistent, and easy to follow.

--

--

Jorge Luis Castro Medina
Jorge Luis Castro Medina

Written by Jorge Luis Castro Medina

I'm a Software Engineer passionate about mobile technologies, and I like everything related to software design and architecture

No responses yet