93

So I stupidly made 3 commits on a machine that was not configured for git (no author or email) and I want to change those 3 commits (have not been pushed) authors to what they are suppose to be.

I know git commit --amend can change the author, but how can I do it to 3? I know rebase can change the message. Is there a way to change author?

2
  • In case others don't see the duplicate message at the top like me, the answer is here stackoverflow.com/a/1320317/292408 Commented May 16, 2020 at 7:54
  • This is not a duplicate question. The flagged question targets multiple commits, while this question only targets the use of rebase.
    – SOFe
    Commented Nov 23, 2020 at 1:32

1 Answer 1

122

You can use interactive rebase. The answer from this post gives you an example: How to change the commit author for one specific commit?.

In particular, you can do the following to change one specific commit:

git commit --amend --author="Author Name <[email protected]>" --no-edit

The author asks for changing author at a specific commit, but interactive rebasing can be used to change authors of multiple commits if you edit all commits that you wish to change.

Other potential useful techniques related to interactive rebasing could be found in the Pro Git book http://git-scm.com/book/en/Git-Tools-Rewriting-History, including squashing, redordering, editing messages, etc.

9
  • 1
    For some reason this doesn't seem to work. It's not changing the author, just the message Commented Mar 6, 2018 at 2:50
  • 73
    You should be able to do it all at once with git rebase BASE_BRANCH --exec 'git commit --amend --author="Author Name <[email protected]>" --no-edit'
    – DylanYoung
    Commented Jul 30, 2020 at 16:53
  • 3
    Note that git rebase --exec ... works technically by running the given command after each commit in the rebased branch. The BASE_BRANCH in comment of @DylanYoung should point to latest commit that you don't want to modify. Everything after that in the current branch will be modifed. Commented Jan 15, 2021 at 9:01
  • 4
    GIT_COMMITTER_NAME="Author Name" GIT_COMMITTER_EMAIL="[email protected]" git commit --amend --author="authorname <[email protected]>" --no-edit This gets committer name update too apart from author. Commented Dec 31, 2021 at 2:53
  • 4
    If you've changed your user then you can rebase, and for each commit, execute a git commit --amend --reset-author --no-edit like this git rebase --exec 'git commit --amend --reset-author --no-edit' BASE
    – CervEd
    Commented Oct 17, 2023 at 11:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.