Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

I was writing a simple script on the school computer, and committing the changes to Git (in a repo that was in my pen drive, cloned from my computer at home). After several commits, I realized I was committing stuff as the root user.

Is there any way to change the author of these commits to my name?

1 Answer

0 votes
by (50.2k points)

For this, you would require to rewrite all history to change its author.

Then for that check out this: https://git-scm.com/docs/git-filter-branch

It includes several examples to get you started

you can fix all the wrong author names and emails for all branches and tags with these commands

#!/bin/sh

git filter-branch --env-filter '

OLD_EMAIL="[email protected]"

CORRECT_NAME="Your Correct Name"

CORRECT_EMAIL="[email protected]"

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

Source: https://help.github.com/en/articles/changing-author-info

Browse Categories

...