0

I was trying to find the answer everywhere on the internet but was unsuccessful.

My problem is that, for some reason, on a new laptop, I put 'email' instead of 'name' and 'password' instead of 'email'. And now, in history, everyone can see my email and its password (facepalm).

So my question is: is there a way to rename the author's name and email in history?

p.s: commit is still in the local branch

screenshot

Ivan Re
  • 17
  • 4
  • 1
    Surely this is a dup of [this question](https://stackoverflow.com/q/73140498/184546). – TTT Jul 28 '22 at 04:25
  • @TTT Not really: here the changes were not pushed yet, so it's a much simpler situation to fix. – joanis Jul 29 '22 at 19:04
  • @joanis I would have thought the same as you since it sort of sounds like it wasn't pushed yet because "commit is still in the local branch". But I had already seen the other question from the day before so I knew... The other question seems to have been written by a co-worker. (What are the odds of this identical problem happening twice within 1 day of each other?) That being said, if the question didn't include the 2nd paragraph, I wouldn't have known it was a dup. – TTT Jul 29 '22 at 19:19
  • 1
    @TTT Good spotting, I should have recognized that since I even answered that duplicate! – joanis Jul 29 '22 at 19:24

2 Answers2

2

You literally can't fix the bad commit, but you can stop using it and then be careful not to send it out to any other Git repository so that no one else can see it.

To make a new-and-improved variant of the existing commit, you must copy the original (bad) one to the new-and-improved one. Copying the last commit on a branch while changing the author information is easy:

git commit --amend --reset-author

will use your current user.name and user.email settings. The existing final commit will be "kicked off the end of the branch", as in this drawing:

...--G--H   <-- somebranch (HEAD)

Here H is the "bad" commit and is the most recent; this is "before git commit --amend". This becomes:

       H
      /
...--G--I   <-- somebranch (HEAD)

Note how commit H is still present in your Git repository, but unless you can find its hash ID, you cannot see commit H any more.

If the "bad" commit is further back in the chain:

...--E--F--G--H   <-- somebranch (HEAD)

where, say, commit F is bad, you have a more difficult task: you must kick commit F off the chain, but this also kicks commits G and H off the chain. This means you must copy F to a new and improved I, and then copy G and H as well. This is harder to do well since git rebase and git cherry-pick want to preserve the original author information, but it's still possible, especially with git rebase -i and git commit --amend.

torek
  • 448,244
  • 59
  • 642
  • 775
0

Simple commit amend fixed the issue. Sorry for the useless post.

git commit --amend --author="Fedor <fedor@bodr.com>"
joanis
  • 10,635
  • 14
  • 30
  • 40
Ivan Re
  • 17
  • 4