Skip to content

Instantly share code, notes, and snippets.

@stigkj
Forked from leif81/git_fix_author
Created December 9, 2011 11:13
Show Gist options
  • Save stigkj/1451142 to your computer and use it in GitHub Desktop.
Save stigkj/1451142 to your computer and use it in GitHub Desktop.
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):
#!/bin/bash
#
# Changes author and committer name and email throughout the whole repository.
# Uses a file with the following format:
#
# [email protected]=John Doe <[email protected]>
# [email protected]=Jill Doe <[email protected]>
#
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
Copy link

ghost commented Apr 17, 2012

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.

@stigkj
Copy link
Author

stigkj commented Apr 17, 2012

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

Copy link

ghost commented Apr 17, 2012

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

@stigkj
Copy link
Author

stigkj commented Apr 18, 2012

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

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