Git Change Commit Message – 6 Easy Ways (Amend Before & After Push)

|

Learn how to change a commit message in Git using simple and safe methods. This guide covers git commit --amend, editing messages before and after push, and best practices to avoid breaking your repository history.

git commit –amend
git rebase -i
–force-with-lease
reword
HEAD~n

When You Need to Change a Git Commit Message

Every developer has been there: you type git commit -m "fxi stuff", press Enter, and immediately wince. Or you push a commit with a vague message like “update” only to confuse your teammates three weeks later during a code review. Knowing how to change a commit message in git is a fundamental skill that keeps your project history clean and meaningful.

Fix a Typo or Unclear Message

The most common reason to git change commit message is a plain old typo. A message like "Adds usre authentication" is both embarrassing and unhelpful. Beyond typos, vague messages like "changes" or "wip" give zero context to anyone reading the log later.

Follow Commit Message Conventions

Many teams enforce commit conventions like Conventional Commits (e.g., feat:fix:chore:). If you forgot the prefix or used the wrong type, editing the message keeps CI checks and changelogs accurate.

Update Incorrect or Missing Information

Sometimes a commit message references the wrong ticket number, describes the wrong behavior, or simply omits the “why.” A corrected message saves hours of archaeology when someone bisects a bug six months from now.

Pro Tip

A great commit message answers what changed and why — not just how. Think of it as a note to your future self and teammates.

Git Change Commit Message Before Push (Safest Way)

Changing a commit message before you push to a remote repository is completely safe — no one else has seen that commit yet, so rewriting it affects only your local history. This is by far the preferred approach whenever possible.

Using the Amend Command

The git commit --amend command opens your default text editor (usually Vim or Nano) with the last commit message pre-populated. You edit the message, save, and close — and Git replaces the commit with a corrected one.

Bash
git commit --amend

# Your editor opens with something like:
Fix usre authentication typo

# Please enter the commit message for your changes.
# Lines starting with '#' will be ignored, and an empty
# message aborts the commit.
#
# Date:      Sat Apr 11 10:22:00 2026 +0200
#
# On branch main
# Your branch is up to date with 'origin/main'.

Edit the first line to your corrected message, then save and close the editor. Git creates a brand-new commit object with the updated message and the same changes as before.

Change Last Commit Message Inline

If you want to skip the editor entirely, pass the new message directly with the -m flag. This is the fastest way to git amend commit message without any interactive prompts:

Bash
# Replace the last commit message in one line
git commit --amend -m "Fix user authentication typo"

[main 3f92a1c] Fix user authentication typo
 Date: Sat Apr 11 10:22:00 2026 +0200
 1 file changed, 4 insertions(+), 2 deletions(-)

Example Workflow

Here’s a complete, realistic scenario of making a commit and then immediately correcting the message:

Example workflow: make a commit → notice the typo → fix it
Bash
# Step 1: Stage your changes
git add src/auth.js

# Step 2: Commit with a typo by mistake
git commit -m "Adds usre login endpoint"
[main a1b2c3d] Adds usre login endpoint

# Step 3: Catch the typo immediately — fix it!
git commit --amend -m "Add user login endpoint"
[main e4f5g6h] Add user login endpoint
 1 file changed, 42 insertions(+)

# Step 4: Verify the corrected message
git log --oneline -1
e4f5g6h (HEAD -> main) Add user login endpoint

Result

The commit history now shows the clean, corrected message. The old commit with the typo is gone. Since you haven’t pushed yet, this is a completely safe operation — no force push needed.

Git Amend Last Commit Message (Quick Fix)

The git amend last commit message workflow is your fastest tool for quick corrections. It’s a one-command operation, but it’s important to understand exactly what it does under the hood — because the side effects matter.

When to Use Amend

  • You’re fixing only the most recent commit (the one pointed to by HEAD)
  • The commit has not been pushed to a shared remote branch
  • You want to also add forgotten files using git add before amending
  • You need to correct the author information using --author

Important Boundary

git commit --amend only touches the last commit. For older commits, you need interactive rebase. Amend cannot reach back two or more commits in the history.

What Happens Internally

This is where many developers get surprised. When you run git commit --amend, Git does not simply update the message in place. It:

  1. Takes the current staging area and the previous commit’s tree
  2. Creates abrand-new commit objectwith the updated message (and a new SHA-1 hash)
  3. Moves the branch pointer (HEAD) to the new commit
  4. Leaves the original commit unreferenced — it will eventually be garbage collected
Internal view: what Git does when you amend
Bash
# BEFORE amend:
a1b2c3d (HEAD -> main) Adds usre login endpoint
9f8e7d6 Add signup form

# AFTER git commit --amend -m "Add user login endpoint":
e4f5g6h (HEAD -> main) Add user login endpoint  ← new hash!
9f8e7d6 Add signup form

# Note: a1b2c3d no longer exists in the visible history
# The commit hash changed because the commit object changed

The key takeaway: commit hash changes are why amending pushed commits causes problems. If you’ve already shared a1b2c3d with teammates, and you replace it with e4f5g6h, their local histories diverge from the remote — leading to conflicts.

Safe Zone Rule

A simple rule: if you haven’t run git push yet, amending is always safe. Once you push, treat the commit as shared history and proceed with caution.

Git Change Commit Message After Push

So you’ve already pushed, and the commit message is wrong. It happens. The question is: how do you git amend commit message after push safely without destroying your team’s workflow? Here are your options — from least to most disruptive.

Amend + Force Push

The most direct way to change git commit message after push without breaking history (for a solo branch or personal fork) is to amend locally and then force-push. Always prefer --force-with-lease over bare --force — it’s a safer variant that fails if someone else pushed to the branch since your last fetch.

Bash
# Step 1: Amend the last commit message locally
git commit --amend -m "Fix login token expiry validation"

# Step 2: Force push using the safer --force-with-lease flag
git push --force-with-lease origin main

Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 312 bytes | 312.00 KiB/s, done.
To github.com:yourname/your-repo.git
 + a1b2c3d...e4f5g6h main -> main (forced update)

–force-with-lease vs –force

--force-with-lease checks that the remote tip matches what you last fetched. If a teammate pushed something while you were amending, the command fails instead of silently overwriting their work. Always prefer it.

Why Force Push Is Dangerous

Force-pushing rewrites the remote branch’s history. Anyone who has pulled from that branch now has a diverged local copy. When they try to push or pull, Git will report conflicts because their history references the old commit hash that no longer exists on the remote.

Danger Scenario: what happens to teammates after a force push
Bash
# Teammate tries to pull after your force push:
git pull origin main

hint: You have divergent branches and need to specify how to reconcile them.
fatal: Need to specify how to handle the diverged branches.

# They now need to reset or rebase to align with the new remote history
git fetch origin
git reset --hard origin/main  # ⚠️ loses their local unpushed work!

Safer Alternative for Teams

If the branch is shared with multiple developers, the safest path is often not to rewrite history at all. Instead:

  • Communicate first — tell your team you’re about to force-push and ask them to stash or pause work on that branch
  • Use a follow-up commit — add a new commit like "docs: correct previous commit message context" (though this doesn’t fix the original message)
  • Use git revert — if the commit introduced bad content (not just a bad message), git revert creates a new undo commit without rewriting history
  • Protect main/master — configure branch protection rules on GitHub/GitLab that block force pushes to shared branches entirely

Golden Rule

Never force-push to mainmaster, or any shared branch without explicit team coordination. Reserve force pushes for your own feature branches only.

Git Edit Older Commit Messages (Interactive Rebase)

What if the bad commit message isn’t the last one? Maybe it’s three commits back in your feature branch. This is where git rebase change commit message comes in — specifically, interactive rebase with the reword action.

Start Interactive Rebase

The -i flag puts rebase in interactive mode. You tell Git how many commits back to include using HEAD~N, where N is the number of recent commits you want to view and potentially edit.

Bash
# Open interactive rebase for the last 3 commits
git rebase -i HEAD~3

# Your editor opens with a list like this:
pick a1b2c3d Add user signup form
pick e4f5g6h Fxi login endpoint validtion    this one has typos
pick i7j8k9l Update README with API docs

# Commands:
# p, pick   = use commit as-is
# r, reword = use commit, but edit the message
# e, edit   = use commit, but stop for amending
# s, squash = merge into previous commit
# d, drop   = remove commit entirely

Change “pick” to “reword”

To edit a commit message, change pick to reword (or just r) on the line of the commit you want to fix. Leave all other lines as pick. Then save and close the editor.

Bash
# Change this:
pick   e4f5g6h Fxi login endpoint validtion

# To this (use 'r' or 'reword'):
reword e4f5g6h Fxi login endpoint validtion

# Save and close → Git pauses and opens the message editor:
Fix login endpoint validation

# Edit, save, close → Git continues replaying commits

Edit Multiple Commit Messages

You can mark multiple commits as reword in the same rebase session. Git will pause at each one, let you edit the message, and then continue to the next. Here’s a full step-by-step example:

  1. Rungit rebase -i HEAD~4to see the last 4 commits in your editor
  2. Changepicktorewordon every commit whose message needs fixing (you can mark multiple lines)
  3. Save and close the rebase todo list
  4. For each marked commit, Git opens the message editor — update it, save, and close
  5. After the last message is saved, Git finishes replaying all commits with the new messages
  6. Verify withgit log --onelineto confirm all messages look correct
BASH — full rebase flow
git rebase -i HEAD~3
# Editor opens — mark two commits as 'reword'

reword a1b2c3d Adds usre signup form     typo
reword e4f5g6h Fxi login endpoint        typo
pick   i7j8k9l Update README

# Save and close. Git opens editor for first commit:
Add user signup form    corrected

# Save, close. Git opens editor for second commit:
Fix login endpoint validation    corrected

# Save, close. Rebase completes:
Successfully rebased and updated refs/heads/feature/auth.

git log --oneline -3
z9y8x7w (HEAD -> feature/auth) Update README
m6n5o4p Fix login endpoint validation
q3r2s1t Add user signup form

Result

All three commits now have clean messages. Because this is a feature branch not yet merged to main, the rewritten hashes are acceptable — just force-push the branch if it’s already on the remote.

Rebase Rewrites All Subsequent Hashes

When you reword a commit with interactive rebase, every commit after it in the chain also gets a new hash, even if their content didn’t change. Plan accordingly before sharing the rebased branch.

Git Commit -m Message Command Example

The best way to avoid needing to git change commit message in the first place is to write great messages from the start. The -m flag lets you write the message inline — but that speed advantage disappears if you rush and produce unclear messages.

Writing Better Commit Messages

  • Use the imperative mood — “Add feature” not “Added feature” or “Adding feature”
  • Keep the subject line under 72 characters — it wraps in most git UIs at this length
  • Capitalize the first word of the subject line
  • No period at the end of the subject line
  • Separate subject from body with a blank line when providing extended detail
  • Explain the why, not just the what — the diff shows what changed; the message explains why

Good vs Bad Examples

The difference between a useful commit log and a useless one comes down to specificity. Here’s how common bad messages translate to better ones:

bad

fix bug
Which bug? In which file? Why did it occur?

good

Fix login validation skipping empty password
Specific, imperative, under 72 chars.

bad

update
Update what? The database? A UI label? A config file?

good

Update API base URL for production environment
Clear context, no ambiguity.

bad

wip
Never commit WIP to a shared branch.

good

feat: add password strength meter to signup form
Conventional Commits format — CI-friendly.

bad

asdfgh
Please don’t do this to your future self.

good

Remove deprecated v1 payment gateway integration
Clear action, meaningful subject.

Multi-line Messages with -m

You can use multiple -m flags to create a subject + body without opening an editor:
git commit -m "Fix cart total rounding" -m "Prices were rounding down instead of using banker's rounding, causing $0.01 discrepancies on large orders."

Common Mistakes When Changing Commit Messages

Even experienced developers make these errors when editing commit history. Knowing them upfront saves you from painful recovery sessions.

Amending Pushed Commits Without Coordination

MISTAKE:
Amending a commit that teammates already pulled

You amend and force-push. Your colleague pulls and gets merge conflicts because their local HEAD points to the old commit hash. They have to manually git fetch and git reset --hard origin/main, potentially losing local work.
Fix: Always check with the team before force-pushing to any shared branch. Use --force-with-lease at minimum, and ideally coordinate on a Slack or Teams thread first.

Losing Commit History with a Wrong Rebase Range

MISTAKE:
Accidentally dropping commits during rebase

During interactive rebase, accidentally deleting a pick line (or changing it to drop) removes that commit from history. If you don’t catch it before completing the rebase, the commit disappears from the branch.
Fix: Use git reflog to find the lost commit and git cherry-pick <hash> to restore it. The reflog keeps a 90-day safety net of all recent HEAD movements.
BASH – recovery with reflog
# Find the lost commit hash in the reflog
git reflog

e4f5g6h HEAD@{0}: rebase -i (finish): returning to refs/heads/feature/auth
...
a1b2c3d HEAD@{5}: commit: Accidentally dropped this one

# Restore it with cherry-pick
git cherry-pick a1b2c3d
[feature/auth b2c3d4e] Accidentally dropped this one

Force Push Conflicts on Protected Branches

MISTAKE:
Trying to force-push to a protected branch

Attempting git push --force-with-lease origin main on a repo with branch protection rules enabled results in a rejected push error. This is intentional — the protection rule exists precisely to prevent history rewrites on critical branches.
Fix: If you absolutely must fix a message on a protected branch, an admin can temporarily disable the protection rule, allow the force-push, and re-enable it immediately after. Document the action in your team’s change log.

Never Use –force on main

Using git push --force (without --lease) on a shared branch is one of the fastest ways to cause serious problems. It overwrites the remote with no safety checks. Always use --force-with-lease or configure branch protection rules to make --force impossible.

Quick Comparison Table

Use this table to quickly pick the right method based on your situation — whether you need to git amend commit message for the last commit or reach further back with rebase.

MethodScopePushed?Rewrites History?SafetyBest For
git commit –amendLast commitNoYes (new hash)✅ SafeQuick pre-push fix
git commit –amend -mLast commitNoYes (new hash)✅ SafeInline one-liner fix
amend + –force-with-leaseLast commitYesYes⚠️ CautionSolo feature branch
git rebase -i (reword)Any recent commitNoYes (chain rewrite)⚠️ CautionOlder commits, pre-push
rebase -i + force-pushAny recent commitYesYes🔴 RiskyCoordinated team effort
New follow-up commitN/A (additive)YesNo✅ SafeShared/protected branches

Git Change Commit Message — The Right Method for Every Situation

Knowing how to git change commit message is one of those skills that separates a developer who maintains a clean, readable history from one who leaves a trail of “fix” and “update” messages behind. The right tool depends entirely on your situation:

If the commit hasn’t been pushed yet, git commit –amend is your fastest, safest friend. For older commits on a local feature branch, interactive rebase with reword gives you surgical control over any message in your recent history. And if the commit is already pushed to a shared branch, tread carefully — coordinate with your team, use --force-with-lease, and consider whether the message is bad enough to justify the disruption.

The underlying principle is simple: rewriting local history is always safe; rewriting shared history always requires communication. Follow that rule, pair it with the comparison table above, and you’ll always know exactly which of these six methods to reach for.

Also see how to Git Remove Last Commit.

Most importantly, invest in writing better commit messages from the start — a clear, imperative-mood message under 72 characters saves far more time than any amend command ever could.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x