Skip to content

Instantly share code, notes, and snippets.

@bgromov
Created June 23, 2016 17:50
Show Gist options
  • Save bgromov/a1905055a8b9cdbeb1d2a87e70920cc8 to your computer and use it in GitHub Desktop.
Save bgromov/a1905055a8b9cdbeb1d2a87e70920cc8 to your computer and use it in GitHub Desktop.
Git: reset author for ALL commits
#!/bin/sh
# Credits: http://stackoverflow.com/a/750191
git filter-branch -f --env-filter "
GIT_AUTHOR_NAME='Newname'
GIT_AUTHOR_EMAIL='new@email'
GIT_COMMITTER_NAME='Newname'
GIT_COMMITTER_EMAIL='new@email'
" HEAD
@billmetangmo
Copy link

Thanks. To update only your commits and not all ( even if not yours):

#!/bin/sh

git filter-branch -f --env-filter '
OLD_EMAIL="xxxxxxxxxxxxxxxxxxxxxxxxxx"
CORRECT_NAME="zzzzzzzzzzzzzzzzz"
CORRECT_EMAIL="yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
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
'  HEAD

Copy link

ghost commented Nov 14, 2022

Thank you so much!

@Irfanwani
Copy link

Thank you very much

@KaduUlson
Copy link

Awesome! Thank you

@miorelli
Copy link

miorelli commented Feb 7, 2023

Thanks a lot.

@PipaStanislav
Copy link

Thanks

@INVISIBLE5130
Copy link

Thank you a lot!

@souravCoder1
Copy link

@bgromov , Newname is our github id or actual name?

both will work.

@smac89
Copy link

smac89 commented May 6, 2024

@biniama

git filter-repo solution:

git filter-repo --preserve-commit-hashes --name-callback "$(cat <<'EOF'
return b'<replace everything between the quotes with your name>'
EOF
)" --email-callback "$(cat <<'EOF'
return b'<replace everything between the quotes with your email>'
EOF
)"

If you had signed your commits before this, note that the above command will remove those signatures. For me, this answer was useful to resign all commits without loosing commit dates.

@snimavat
Copy link

Works good, except merge commits, where it still shows the another user

@jbcr
Copy link

jbcr commented Oct 28, 2024

Work fine. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment