Skip to content

Commit 0f9a743

Browse files
committed
Add git-change-author script
1 parent a198a35 commit 0f9a743

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ git clone this repository, then add it to your `$PATH`. Nothing here actually re
9090
## Credits
9191

9292
* git-big-file - Mislav Marohnić's [dotfiles](https://github.com/mislav/dotfiles)
93+
* git-change-author - Michael Demmer in [jut-io/git-scripts](https://github.com/jut-io/git-scripts/blob/master/bin/git-change-author)
9394
* git-changes - Michael Markert's [dotfiles](https://github.com/cofi/dotfiles)
9495
* git-churn - Gary Bernhardt's [dotfiles](https://github.com/garybernhardt/dotfiles/blob/master/bin/git-churn)
9596
* git-copy-branch-name - Zach Holman's [dotfiles](https://github.com/holman/dotfiles)

git-change-author

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
# Author: Michael Demmer https://github.com/demmer
3+
# License: MIT
4+
# Original source: https://github.com/jut-io/git-scripts/blob/master/bin/git-change-author
5+
6+
prog=`basename $0`
7+
8+
force=
9+
if [ "$1" == "-f" ] ; then
10+
force="-f"
11+
shift;
12+
fi
13+
14+
old_email=$1; shift;
15+
new_author=$1; shift;
16+
new_email=$1; shift;
17+
18+
if test -z "$old_email" -o -z "$new_author" -o -z "$new_email" ; then
19+
echo "usage: $prog <old_email> <new_author> <new_email>"
20+
echo ""
21+
echo "example: $prog [-f] user@old.server.com \"User Name\" user2@new.server.com"
22+
exit 1
23+
fi
24+
25+
echo "Rewriting commits for $old_email to $new_author <$new_email>"
26+
27+
export old_email
28+
export new_author
29+
export new_email
30+
31+
git filter-branch $force --env-filter '
32+
an="$GIT_AUTHOR_NAME"
33+
am="$GIT_AUTHOR_EMAIL"
34+
cn="$GIT_COMMITTER_NAME"
35+
cm="$GIT_COMMITTER_EMAIL"
36+
37+
if [ "$GIT_COMMITTER_EMAIL" = "$old_email" ]
38+
then
39+
cn=$new_author
40+
cm=$new_email
41+
fi
42+
if [ "$GIT_AUTHOR_EMAIL" = "$old_email" ]
43+
then
44+
an=$new_author
45+
am=$new_email
46+
fi
47+
48+
export GIT_AUTHOR_NAME="$an"
49+
export GIT_AUTHOR_EMAIL="$am"
50+
export GIT_COMMITTER_NAME="$cn"
51+
export GIT_COMMITTER_EMAIL="$cm"
52+
' $*

0 commit comments

Comments
 (0)