Git
Version Control
Commit Author
Git Rebase
Git Amend

How can I change the commit author for a single commit?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Changing the author of a Git commit is a history rewrite operation, so it is simple technically but sensitive operationally. The method depends on whether the commit is the latest one or an older commit in branch history. A safe workflow updates metadata, verifies results, and coordinates any force push when history was already shared.

Know the Metadata You Are Changing

Git stores at least two identities per commit:

  • Author: original writer of the change.
  • Committer: person who created the commit object.

When you amend or rebase, committer metadata is updated by default. Author metadata changes only if you set it explicitly.

Check current details first:

bash
git show --no-patch --pretty=fuller HEAD

This gives a baseline before rewriting.

Change Author on the Most Recent Commit

If target commit is HEAD, use amend with explicit author value.

bash
git commit --amend --author="Jane Doe <[email protected]>"

This opens editor for commit message. Keep message unchanged if only author must change.

If you want to keep message non-interactively:

bash
git commit --amend --author="Jane Doe <[email protected]>" --no-edit

Verify the result:

bash
git show --no-patch --pretty=format:'%h %an <%ae> | %cn <%ce> | %s' HEAD

Remember hash changes after rewrite.

Change Author on an Older Commit

For a non-latest commit, use interactive rebase and mark the target commit for edit.

bash
# Example: target is within last 6 commits
git rebase -i HEAD~6

In opened todo list, replace pick with edit on target line. Rebase stops at that commit.

Then run:

bash
git commit --amend --author="Jane Doe <[email protected]>" --no-edit
git rebase --continue

If conflicts appear, resolve them, stage files, and continue. All descendant commit hashes in that range will change.

Push Rewritten History Safely

If rewritten commits were already pushed, normal push will fail due to non-fast-forward history. Use lease-protected force push.

bash
git push --force-with-lease origin your-branch

--force-with-lease is safer than plain --force because it fails if remote moved unexpectedly.

Before push, notify teammates. Anyone with the old branch history may need to rebase or reset local copies.

Multi-Author and Pairing Scenarios

Sometimes author should reflect pair programming attribution while committer stays as the person who executed commands. In such cases, set author explicitly and keep committer identity normal. If repository policy uses trailer metadata for co-authors, keep trailers in commit message after amend.

Example trailer:

text
Co-authored-by: Partner Name <[email protected]>

Do not confuse trailers with main author identity. Both can coexist.

Prevent Future Author Mistakes

Most corrections are avoidable with proper configuration.

bash
1# Repo-specific identity
2git config user.name "Jane Doe"
3git config user.email "[email protected]"
4
5# Optional global defaults
6git config --global user.name "Jane Doe"
7git config --global user.email "[email protected]"

For multiple accounts, use repository-level config or conditional includes so work and personal identities do not mix.

Signed Commit and CI Implications

Rewriting commits changes hashes and invalidates existing commit signatures. If project enforces signed commits, re-sign rewritten commits before push. Also note that CI systems tied to old hashes may show stale status until the branch is updated. For active pull requests, announce the rewrite so reviewers can refresh local branches and avoid duplicate review comments on outdated commit IDs.

Common Pitfalls

A common mistake is rewriting shared history without warning collaborators, causing accidental divergence and confusion. Another is using a rebase range that misses the target commit or includes too much history. Teams also use plain --force and overwrite remote updates from others. Signed commit repositories often forget re-signing after amend. Finally, some developers fix author but do not verify metadata, then discover later that committer changed but author did not. The command is short, but the coordination cost can be larger than the edit itself.

Summary

  • Use git commit --amend --author for the latest commit.
  • Use interactive rebase with edit for older commits.
  • Verify rewritten metadata immediately with git show.
  • Push rewritten history with --force-with-lease.
  • Coordinate with teammates before rewriting shared branch history.
  • Configure identity per repository to prevent repeat fixes.

Course illustration
Course illustration

All Rights Reserved.