Skip to content

Instantly share code, notes, and snippets.

@ianmariano
Created June 19, 2014 21:46
Show Gist options
  • Save ianmariano/af338de14ff7f28ced77 to your computer and use it in GitHub Desktop.
Save ianmariano/af338de14ff7f28ced77 to your computer and use it in GitHub Desktop.
Rewrite an author/committer in your git history. Place on your path and do: git change-committer name new_name new_email
#!/bin/bash
usage() {
echo "$0 usage:"
echo " $0 name new_name new_email"
exit 1
}
if [ "$#" -ne 3 ]; then
usage
fi
if ! git diff --quiet; then
echo "You have uncommitted changes."
exit 1
fi
export oa="$1"
export na="$2"
export ne="$3"
git filter-branch --env-filter '
an="$GIT_AUTHOR_NAME"
ae="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
ce="$GIT_COMMITTER_EMAIL"
if [ "$an" = "$oa" ]; then
an="$na"
ae="$ne"
cn="$na"
ce="$ne"
fi
export GIT_AUTHOR_NAME="$an"
export GIT_AUTHOR_EMAIL="$ae"
export GIT_COMMITTER_NAME="$cn"
export GIT_COMMITTER_EMAIL="$ce"
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment