-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-change-author
executable file
·49 lines (40 loc) · 968 Bytes
/
git-change-author
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
43
44
45
46
47
48
49
#!/bin/sh
prog=`basename $0`
force=
if [ "$1" == "-f" ] ; then
force="-f"
shift;
fi
old_email=$1; shift;
new_author=$1; shift;
new_email=$1; shift;
if test -z "$old_email" -o -z "$new_author" -o -z "$new_email" ; then
echo "usage: $prog <old_email> <new_author> <new_email>"
echo ""
echo "example: $prog [-f] [email protected] \"User Name\" [email protected]"
exit 1
fi
echo "Rewriting commits for $old_email to $new_author <$new_email>"
export old_email
export new_author
export new_email
git filter-branch $force --env-filter '
an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"
if [ "$GIT_COMMITTER_EMAIL" = "$old_email" ]
then
cn=$new_author
cm=$new_email
fi
if [ "$GIT_AUTHOR_EMAIL" = "$old_email" ]
then
an=$new_author
am=$new_email
fi
export GIT_AUTHOR_NAME="$an"
export GIT_AUTHOR_EMAIL="$am"
export GIT_COMMITTER_NAME="$cn"
export GIT_COMMITTER_EMAIL="$cm"
' $*