80

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?

Steven
  • 13,250
  • 33
  • 95
  • 147
  • In case others don't see the duplicate message at the top like me, the answer is here https://stackoverflow.com/a/1320317/292408 – Elijah Lynn May 16 '20 at 07:54
  • This is not a duplicate question. The flagged question targets *multiple* commits, while this question only targets the use of rebase. – SOFe Nov 23 '20 at 01:32

1 Answers1

106

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@address.com>" --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.

DylanYoung
  • 2,423
  • 27
  • 30
Yang
  • 7,712
  • 9
  • 48
  • 65
  • The Pro Git chapter you reference also mentions using `git filter-branch --commit-filer` to do this same thing, but unless you're proficient in bash scripting, it's probably harder to use vs the interactive rebase. –  Apr 25 '13 at 15:06
  • @ColdHawaiian Thanks for your comment. I was trying to provide a more comprehensive reference to the interactive rebasing tool and should state more clearly. – Yang Apr 25 '13 at 15:12
  • 1
    For some reason this doesn't seem to work. It's not changing the author, just the message – Joe Phillips Mar 06 '18 at 02:50
  • 58
    You should be able to do it all at once with `git rebase BASE_BRANCH --exec 'git commit --amend --author="Author Name " --no-edit'` – DylanYoung Jul 30 '20 at 16:53
  • Also: please provide context for links https://stackoverflow.com/help/how-to-answer – DylanYoung Jul 30 '20 at 16:55
  • 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. – Mikko Rantalainen Jan 15 '21 at 09:01
  • 1
    @DylanYoung's command worked perfectly for me! Thank you! (macOS catalina, git v2.32.0) – Devin Rhode Aug 09 '21 at 23:20
  • 4
    `GIT_COMMITTER_NAME="Author Name" GIT_COMMITTER_EMAIL="author@email.com" git commit --amend --author="authorname " --no-edit` This gets committer name update too apart from author. – enthusiasticgeek Dec 31 '21 at 02:53