-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrewrite-git-author.sh
More file actions
executable file
·80 lines (69 loc) · 2.42 KB
/
rewrite-git-author.sh
File metadata and controls
executable file
·80 lines (69 loc) · 2.42 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
#
# Git Author Rewrite Script
# This script rewrites all commits to change author information
# WARNING: This rewrites Git history!
#
cd /Users/tamahant/Documents/GitHub/flexgate-proxy
echo "=========================================="
echo "Git Author Rewrite Script"
echo "=========================================="
echo ""
echo "This will rewrite ALL commits across ALL branches to:"
echo " Author: tapas100 <mahanta.tapas9@gmail.com>"
echo ""
echo "WARNING: This rewrites Git history!"
echo "You will need to force push all branches after this."
echo ""
read -p "Continue? (yes/no): " confirm
if [ "$confirm" != "yes" ]; then
echo "Aborted."
exit 1
fi
echo ""
echo "Starting Git history rewrite..."
echo ""
# Use git filter-branch to rewrite all commits
git filter-branch --env-filter '
# New author information
CORRECT_NAME="tapas100"
CORRECT_EMAIL="mahanta.tapas9@gmail.com"
# Rewrite all Cisco emails
if [ "$GIT_COMMITTER_EMAIL" = "tamahant+cisco@cisco.com" ] || \
[ "$GIT_COMMITTER_EMAIL" = "tamahant@cisco.com" ] || \
[ "$GIT_AUTHOR_EMAIL" = "tamahant+cisco@cisco.com" ] || \
[ "$GIT_AUTHOR_EMAIL" = "tamahant@cisco.com" ]; then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
# Also fix any commits with "Tapas Mahanta" name but wrong email
if [ "$GIT_AUTHOR_NAME" = "Tapas Mahanta" ] && \
[ "$GIT_AUTHOR_EMAIL" != "mahanta.tapas9@gmail.com" ]; then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
# Also fix the -X format
if [[ "$GIT_AUTHOR_NAME" == *"tamahant"* ]]; then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
echo ""
echo "=========================================="
echo "Git history rewrite complete!"
echo "=========================================="
echo ""
echo "Next steps:"
echo "1. Verify the changes: git log --format='%an <%ae>' | sort | uniq"
echo "2. Force push ALL branches:"
echo " git push --force --all origin"
echo " git push --force --tags origin"
echo ""
echo "IMPORTANT: All collaborators will need to re-clone the repository!"
echo ""