Renaming a Commit in a Pull Request (Conventional Commits Style)
Clear and consistent commit messages make your Git history easier to understand, review, and automate. In many teams, developers follow the Conventional Commits convention, where commit messages follow a strict format like:
feat: add new user registration flow
fix: handle edge case in pricing logic
docs: update API usage examples
If you've already pushed a commit and realize it needs renaming—for clarity, convention, or feedback—you can rename it using interactive rebase.
Key Concepts
-
Why Rename a Commit? To clarify the commit’s purpose, correct formatting, or align with a commit style guide (e.g., Conventional Commits).
-
What Are Conventional Commits? A standardized format for commit messages that makes history easier to parse for humans and tools alike. Example:
type(scope): subject
type
: feat, fix, docs, refactor, test, chore, etc.scope
: optional; e.g.,auth
,api
,ui
subject
: short, imperative sentence (no period)
Step-by-Step: How to Rename a Commit
We’ll walk through renaming a commit using git rebase -i
, with an animated terminal demo below.
1. Check Your Recent Commits
git log --oneline
h7i8j9k docs(readme): update API usage
d4e5f6g feat(ui): add spacing utility classes
a1b2c3d fix(layout): correct mobile nav overflow
Suppose we want to rename feat(ui): add spacing utility classes
.
2. Start Interactive Rebase
Count how many commits back the target is. In this case, 2.
git rebase -i HEAD~3
3. Interactive Editor Opens
pick a1b2c3d fix(layout): correct mobile nav overflow
pick d4e5f6g feat(ui): add spacing utility classes
pick h7i8j9k docs(readme): update API usage
Change pick
to reword
for the commit to rename:
pick a1b2c3d fix(layout): correct mobile nav overflow
reword d4e5f6g feat(ui): add spacing utility classes
pick h7i8j9k docs(readme): update API usage
Save and close (:wq
in Vim).
4. Enter the New Commit Message
You'll be prompted to enter a new message:
feat(ui): add utility classes for margin and padding
Make the message specific and Conventional Commit-compliant. Save and exit.
5. Force Push the Updated History
git push origin your-branch-name --force
This updates the remote branch used in your PR with the renamed commit.
Conclusion
Renaming a commit using git rebase -i
is a clean and controlled way to maintain a meaningful Git history—especially when paired with the Conventional Commits format. This not only improves collaboration and reviewability but also supports automated tools like changelog generators and CI pipelines.
Well-written commits = professional, maintainable projects.