-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-reauthor.sh
More file actions
executable file
·70 lines (57 loc) · 2.55 KB
/
git-reauthor.sh
File metadata and controls
executable file
·70 lines (57 loc) · 2.55 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
#!/bin/sh
old_email=${1:-"incorrect@email"}
curr_email=`git config --get user.email`
curr_name=`git config --get user.name`
new_email=${2:-"$curr_email"}
new_name=${3:-"$curr_name"}
if [ "$old_email" = "-h" ]; then
echo ""
echo "usage: git-reauthor.sh -h"
echo " git-reauthor.sh -d"
echo " git-reauthor.sh user@email_host.com"
echo ""
echo "-h This help message"
echo "-d Delete the original/refs/ branches"
echo ""
echo "This script will rename all commits authored by 'user@email_host.com', if either the"
echo "author name, or author email address matches the string provided. Once the results"
echo "have been verify (manually, with something like gitk --all), then run git-reauthor -d"
echo "to delete of the origin/refs branches that are created"
echo ""
#
# NOTE: Changing the authors changes the SHA1 of each commit changed! So, it
# re-writes history. USE WITH CAUTION!
#
elif [ "$old_email" != "-d" ]; then
echo "new_email = $new_email"
echo "new_name = $new_name"
# From http://stackoverflow.com/questions/4981126/how-to-amend-several-commits-in-git-to-change-author
git filter-branch --env-filter "if [ \"\$GIT_AUTHOR_EMAIL\" = \"$old_email\" ] || [ \"\$GIT_AUTHOR_NAME\" = \"$old_email\"]; then
export GIT_AUTHOR_EMAIL=$new_email;
export GIT_AUTHOR_NAME=\"$new_name\";
export GIT_COMMITTER_EMAIL=\"\$GIT_AUTHOR_EMAIL\";
export GIT_COMMITTER_NAME=\"\$GIT_AUTHOR_NAME\"; fi" -- --all
# From http://stackoverflow.com/questions/4981126/how-to-amend-several-commits-in-git-to-change-author
#git rebase -i HEAD~19 -x "git commit --amend --author 'Russell Brinkmann<russell_brinkmann@trimble.com>' --no-edit"
# From https://www.git-tower.com/learn/git/faq/change-author-name-email
#$ git filter-branch --env-filter '
#WRONG_EMAIL="wrong@example.com"
#NEW_NAME="New Name Value"
#NEW_EMAIL="correct@example.com"
#
#if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
#then
# export GIT_COMMITTER_NAME="$NEW_NAME"
# export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
#fi
#if [ "$GIT_AUTHOR_EMAIL" = "$WRONG_EMAIL" ]
#then
# export GIT_AUTHOR_NAME="$NEW_NAME"
# export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
#fi
#' --tag-name-filter cat -- --branches --tags
else
# Once complete, the refs/original branch can be deleted:
# http://stackoverflow.com/questions/7654822/remove-refs-original-heads-master-from-git-repo-after-filter-branch-tree-filte
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
fi