Skip to content

Instantly share code, notes, and snippets.

@gwpl
Created December 8, 2019 09:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwpl/dbf993223c8433767c81925513bef656 to your computer and use it in GitHub Desktop.
Save gwpl/dbf993223c8433767c81925513bef656 to your computer and use it in GitHub Desktop.
# solution from https://blog.tinned-software.net/rewrite-author-of-entire-git-repository/
git fetch origin
git reset --hard origin/master
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
git reflog expire --expire=now --all
git gc --prune=now
# from https://stackoverflow.com/a/11768843/544721
# Source: https://github.com/brauliobo/gitconfig/blob/master/configs/.gitconfig
# You can add this alias:
git config alias.change-commits '!'"f() { VAR=\$1; OLD=\$2; NEW=\$3; shift 3; git filter-branch --env-filter \"if [[ \\\"\$\`echo \$VAR\`\\\" = '\$OLD' ]]; then export \$VAR='\$NEW'; fi\" \$@; }; f "
To change the author name:
# git change-commits GIT_AUTHOR_NAME "old name" "new name"
# or the email for only the last 10 commits:
# git change-commits GIT_AUTHOR_EMAIL "old@email.com" "new@email.com" HEAD~10..HEAD
# Alias:
# change-commits = "!f() { VAR=$1; OLD=$2; NEW=$3; shift 3; git filter-branch --env-filter \"if [[ \\\"$`echo $VAR`\\\" = '$OLD' ]]; then export $VAR='$NEW'; fi\" \$@; }; f "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment