-
Notifications
You must be signed in to change notification settings - Fork 3
/
git-name-change
executable file
·53 lines (40 loc) · 1.27 KB
/
git-name-change
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
50
51
52
53
#!/bin/sh
# Clones a repo then changes the name and email address in entire history.
usage() {
echo "usage: ${0##*/} REPO_URL OLD_EMAIL NEW_NAME NEW_EMAIL" >&2
echo "clones the given repo, changing the name and email address in entire history" >&2
exit 1
}
if echo "$*" | grep -Eq -- '--help\b|-h\b'; then
usage
fi
REPO_URL="$1"
shift
OLD_EMAIL="$1"
shift
NEW_NAME="$1"
shift
NEW_EMAIL="$1"
shift
if [ -z "$REPO_URL" ] || [ -z "$OLD_EMAIL" ] || [ -z "$NEW_NAME" ] || [ -z "$NEW_EMAIL" ]; then
usage
fi
REPO_DIR=rewrite.tmp
# Clone the repository
git clone "$REPO_URL" "$REPO_DIR"
# Change to the cloned repository
cd "$REPO_DIR" || exit 1
# Checkout all the remote branches as local tracking branches
git branch --list -r origin/* | cut -c10- | xargs -n1 git checkout
# Rewrite the history, use a system that will preserve the eol
# (or lack of in commit messages) - preferably Linux not OSX
git filter-branch -f --env-filter "
if [ \"\$GIT_COMMITTER_EMAIL\" = \"$OLD_EMAIL\" ]; then
export GIT_COMMITTER_NAME=\"$NEW_NAME\"
export GIT_COMMITTER_EMAIL=\"$NEW_EMAIL\"
fi
if [ \"\$GIT_AUTHOR_EMAIL\" = \"$OLD_EMAIL\" ]; then
export GIT_AUTHOR_NAME=\"$NEW_NAME\"
export GIT_AUTHOR_EMAIL=\"$NEW_EMAIL\"
fi
" --tag-name-filter cat -- --all --branches --tags