LinuxCommandLibrary

git-reauthor

Correct commit authorship information

TLDR

Change an author's email and name across the whole Git repository

$ git reauthor --old-email [old@example.com] --correct-email [new@example.com] --correct-name "[name]"
copy

Change the email and name to the ones defined in the Git config
$ git reauthor --old-email [old@example.com] --use-config
copy

Change the email and name of all commits, regardless of their original author
$ git reauthor --all --correct-email [name@example.com] --correct-name [name]
copy

SYNOPSIS

git reauthor [options] []

PARAMETERS


    Specifies the range of commits to reauthor. If omitted, it defaults to HEAD.
Example: `HEAD~3..HEAD`

--old-author=
    Specifies the old author pattern, use this to find the commits to change.

--new-author='Author Name '
    The new author information to set.

DESCRIPTION

The `git-reauthor` command is not a standard Git command, but rather a custom script or alias. It is designed to modify the author information (name and email) of one or more commits in a Git repository. Such functionality is useful to correct mistakes in authorship, attributing commits to their rightful author or anonymizing author information to maintain privacy. Without a `git-reauthor` script defined, the command will return an error. Commonly it is a shell script utilizing `git filter-branch` or `git commit --amend --author=...` to rewrite the commit history. Since these methods rewrite history, the command should be used with caution, especially in shared repositories because of breaking references if pushed with rewrite history enabled.

CAVEATS

Rewriting commit history can cause significant issues if the changes are pushed to shared repositories because it changes commit SHAs.
Collaboration with others who have already based their work on the original history becomes difficult.

IMPLEMENTATION NOTES

A typical implementation might involve a loop that iterates through the specified commits, extracts the commit message, and uses `git commit --amend --author` to modify the author information. Error handling and validation should be added to protect the data integrity.

HISTORY

The `git-reauthor` command is not a standard Git command and hence doesn't have official history. It's often implemented as a custom script or alias built upon other Git commands like `git filter-branch` or `git commit --amend` to rewrite the commit history. The need for such functionality arises when author information needs to be corrected or modified in Git repositories.
The use of `git filter-branch` is becoming less common due to performance issues. The alternatives are interactive rebasing or using `git commit --amend` for the recent commit.

SEE ALSO

git filter-branch(1), git commit(1), git rebase(1)

Copied to clipboard