public
Last active — forked from leif81/git_fix_author

Written to change the unix name used for a cvs commit to a pretty git name for the user.Implementation borrowed from http://lists.freedesktop.org/archives/portland/2010-October.txtauthor-conv-file format (same format as git-cvsimport requires):

  • Download Gist
git-fix-author
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#!/bin/bash
#
# Changes author and committer name and email throughout the whole repository.
# Uses a file with the following format:
#
# john.doe@hotmail.com=John Doe <john.doe@hotmail.com>
# jill.doe@hotmail.com=Jill Doe <jill.doe@hotmail.com>
#
 
if [ ! -e "$1" ]
then
echo "File '$1' does not exist"
exit 1
fi
 
export authors_file=$1
 
git filter-branch -f --env-filter '
grep "^$GIT_COMMITTER_EMAIL=" "$authors_file" >> /dev/null
RETVAL=$?
 
if [ $RETVAL -eq 0 ]
then
get_name () {
grep "^$1=" "$authors_file" |
sed "s/^.*=\(.*\) <.*>$/\1/"
}
get_email () {
grep "^$1=" "$authors_file" |
sed "s/^.*=.* <\(.*\)>$/\1/"
}
name=$(get_name "$GIT_COMMITTER_EMAIL")
email=$(get_email "$GIT_COMMITTER_EMAIL")
 
GIT_AUTHOR_NAME="$name" &&
GIT_AUTHOR_EMAIL="$email" &&
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" &&
GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
fi
' -- --all

Improved implementation by

  • taking the auth-conv-file to use as an argument
  • use email as key instead of name to get around the problem with foreign letters
  • more quoting

Can this be adopted to include a list of Git contributors emails -- not a cvs import -- and then go through the list? Change the user and email based only on the old email.

You mean you do not have a file, just a list inline in the script?

Having a file, but only base the cycle on emails, and end up with one author(name+email).

Not sure I understand...it is based on emails, that is, commits with emails matching the first column in the file will get their name and email replaced from the second column of the file

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.