This repository has been archived by the owner on Oct 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changemail.sh
66 lines (51 loc) · 1.54 KB
/
changemail.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
if [ -z "$1" ]
then
echo "missing remote repository name"
echo "usage: $0 <repo-name> <user-name> <user-mail>"
echo "ex: $0 origin bob bob@leponge.fr"
exit 1
fi
origin=mailmap
remote=$(git remote get-url $1)
echo "Using alias <$origin> for repository <$remote>"
if [ -z "$2" ]
then
echo "missing new name"
echo "usage: $0 <repo-name> <user-name> <user-mail>"
echo "ex: $0 origin bob bob@leponge.fr"
exit 1
fi
if [ -z "$3" ]
then
echo "missing new email"
echo "usage: $0 <repo-name> <user-name> <user-mail>"
echo "ex: $0 origin bob bob@leponge.fr"
exit 1
fi
name=$2
email=$3
echo "Will change all emails to: $name <$email>"
filter="s/^[^a-zA-Z]*/$name <$email> /"
git shortlog --summary --numbered --email | sed -e "$filter" > /tmp/mailmap
git filter-repo --mailmap /tmp/mailmap --force
git remote add $origin $remote
git push --set-upstream $origin main --force
git push --set-upstream $origin develop --force
git reset --hard $origin/main
git reset --hard $origin/develop
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
grep -v 'refs/replace' .git/packed-refs > /tmp/packref
mv /tmp/packref .git/packed-refs
git gc --prune=now
git gc --aggressive --prune=now
git push origin --all
git config --global --unset-all user.email
git config --global --unset-all user.name
git config --unset-all user.email
git config --unset-all user.name
git config user.name $name
git config user.email $email