Can you *really* change the author in Git

Viewed 67

Sounds like a standard "can I change the author of a Git commit" question but it's not really...

...my question is given you have changed an author via git commit --amend --author="Dr Evil <dr.evil@worlddomination.org>" is it really lost? Can it be recovered if the reflog for example?

What about other scenarios? I know a author can naturally change after a squash/rebase type activity, but I assume in those cases, you still have the history in the tree somewhere? How can it be retrieved?

Any kind of summary about recovering this kind of thing or even pulling it out in a report would be very helpful. I'm concerned with auditing and showing the author can't be nefariously faked. I appreciate the signature can help here but vaguely remember that if an author changes, the new author would themselves sign the commit - so it doesn't ensure anything other than the (potentially up to no good new) author is who she says she is.

1 Answers

The author on an existing commit can be changed (or "faked" if you will). But technically that is only because it is being replaced by a new commit, that is identical to the old one, except that the author is different and consequently the hash of the commit is different.

The commit with the original author (and original hash) is still in the reflog. By default the reflog only retains commits for 2 weeks.

The most straightforward way to prevent wanton rewriting of history is to prevent ordinary users from using push -f. This is done via a pre-commit hook. Once a particular history has been pushed, there is no way to "rewrite" it except with a push -f.

Related