DEV Community

Cover image for Changing the Git history
Ezequiel Esnaola
Ezequiel Esnaola

Posted on • Edited on

3

Changing the Git history

After a month of having formatted my work computer, I noticed that my mail configured in GIT was wrong. This caused my commits to not recognize me as the author and not appear on my account activity.

If this error is detected after a single commit, it can be easily solved with the following command:

git commit --amend --author="Correct Name <youremail@example.com>"
Enter fullscreen mode Exit fullscreen mode

If it is detected after several commits, as happened to me, the best solution is this:

#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

I hope you enjoyed my first post ever on dev.to!

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more