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
CodePudding user response:
Simple commit amend fixed the issue. Sorry for the useless post.
git commit --amend --author="Fedor [email protected]"
CodePudding user response:
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
.