Skip to content

Commit 8a58df6

Browse files
author
anttiharju
committed
Save deprecate-email script
For many years this was in a Google Keep note, so really good to properly version control it now.
1 parent 22faf0d commit 8a58df6

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

bin/deprecate-email

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env dash
2+
set -eu
3+
4+
# deprecate-email:
5+
# Sometimes I remove email addresses from my GitHub profile. This makes the contributions in my profile disappear as the email address is no longer associated with my account. This script replaces commits with input email with current git config.
6+
7+
if [ -z "$1" ]; then
8+
echo "Error: old_email argument is required."
9+
exit 1
10+
fi
11+
12+
old_email="$1"
13+
new_email="$(git config user.email)"
14+
new_name="$(git config user.name)"
15+
16+
# Replacing author and committer emails has to be done separately to avoid unintentional overwrites
17+
# e.g. in commits with multiple authors.
18+
(export FILTER_BRANCH_SQUELCH_WARNING=1 && \
19+
echo "1/2 Overwriting committer" && \
20+
git filter-branch -f --commit-filter "
21+
if [ \"\$GIT_COMMITTER_EMAIL\" = \"$old_email\" ];
22+
then
23+
GIT_COMMITTER_NAME=\"$new_name\";
24+
GIT_COMMITTER_EMAIL=\"$new_email\";
25+
git commit-tree \"\$@\";
26+
else
27+
git commit-tree \"\$@\";
28+
fi" HEAD && \
29+
echo "2/2 Overwriting author" && \
30+
git filter-branch -f --commit-filter "
31+
if [ \"\$GIT_AUTHOR_EMAIL\" = \"$old_email\" ];
32+
then
33+
GIT_AUTHOR_NAME=\"$new_name\";
34+
GIT_AUTHOR_EMAIL=\"$new_email\";
35+
git commit-tree \"\$@\";
36+
else
37+
git commit-tree \"\$@\";
38+
fi" HEAD)

0 commit comments

Comments
 (0)