Conversation with Gemini

You said

git change author and email without changing timestamps

Gemini said

To change the author name and email for past commits while preserving original author and committer timestamps, you can use an interactive rebase combined with an exec command that locks down the dates.

Step 1: Set your new Git configuration

Make sure your local environment is set to the new name and email you want to apply:

Bash
git config user.name "Your New Name"
git config user.email "your.new.email@example.com"

Step 2: Run the automated rebase command

Choose the scope of history you want to change:

  • For the last commits (e.g., last 5 commits):

    Bash
    git -c rebase.instructionFormat='%s%nexec GIT_COMMITTER_DATE="%cD" GIT_AUTHOR_DATE="%aD" git commit --amend --no-edit --reset-author' rebase -i HEAD~5
    
  • For the entire repository history (from the root):

    Bash
    git -c rebase.instructionFormat='%s%nexec GIT_COMMITTER_DATE="%cD" GIT_AUTHOR_DATE="%aD" git commit --amend --no-edit --reset-author' rebase -i --root
    

[!NOTE] When your text editor pops open with the rebase instructions, leave everything as pick and just save and close the file. The -c rebase.instructionFormat trick automatically injects the command to amend the author/email while extracting and locking in the original %cD (committer date) and %aD (author date).

Step 3: Force push your changes (if already published)

Because rewriting history changes commit hashes, you will need to force-push the updated branch to your remote repository:

Bash
git push origin <branch-name> --force-with-lease


Gemini is AI and can make mistakes.