You committed for a month with the wrong email address. How do you fix authorship?
IntermediateScenarioRebase, Cherry-pick and History Rewriting
Answer
Situation read → Commits carry author and committer identity that you can rewrite only by creating new commits.
What I'd do →
- Fix config:
git config user.email "[email protected]". - Unpushed or private branch:
git rebase -r --root --exec 'git commit --amend --no-edit --reset-author'. - Whole repo with a mapping: use
git filter-repo --mailmap mailmap.txt. - Force-push, and warn collaborators to re-clone.
Why → Identity is part of the commit hash, so changing it changes every descendant SHA.
Interview tip → For display-only fixes, a .mailmap file changes git log and shortlog output without rewriting history.
More on Rebase, Cherry-pick and History Rewriting
Your PR branch has ten commits like "wip", "fix typo", "oops". How do you clean it up before review?BeginnerYou want the database migration commit to come before the code that uses it.BeginnerA critical fix on `main` must go to the `release/4.1` branch only.BeginnerYou must backport a feature made of 6 commits, including one merge commit.IntermediateBranch B was built on top of branch A. A was squash-merged into `main`, and now B shows A's commits again.IntermediateDuring review you get ten small change requests on old commits. How do you apply them cleanly?Intermediate