-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgit-change-author
executable file
·48 lines (39 loc) · 2.08 KB
/
git-change-author
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
#!/bin/bash
##########################################################################
# git-change-author: Git Bulk Commit Author Rewriter #
# #
# Easily change the name and email of any of the commits in #
# a git repository. #
# #
# ./git-change-author "Your Name" "email@address" <SHA1> #
# #
# Part of HopeSeekr's BashScripts Collection #
# https://github.com/hopeseekr/BashScripts/ #
# #
# Copyright © 2012-2021 Theodore R. Smith <[email protected]> #
# GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690 #
# #
# License: Creative Commons Attribution v4.0 International #
# #
##########################################################################
if [[ -z "$1" || "$1" == "--help" || -z "$2" ]]; then
echo ' Usage: git-change-author "Your Name" "email@address" [SHA1]'
exit 1
fi
AUTHOR="$1"
EMAIL="$2"
START_HASH="${3:---root}"
echo "On the next screen, you need to change 'pick' to 'edit' for every commit which you wish to alter."
echo ""
echo -n "Press ENTER to continue..."
read
git rebase --rebase-merges -i ${START_HASH}
while [ "$?" -eq 0 ]; do
git -c user.name="${AUTHOR}" -c user.email="${EMAIL}" commit --amend --no-edit --author "${AUTHOR} <${EMAIL}>"
git rebase --continue
done
# Reset the git commit times so that GitHub, et. al., will show the original date and not now.
git rebase --rebase-merges --committer-date-is-author-date "${START_HASH}"
echo ""
echo ""
echo "Don't forget to run \`git push -f\`... preferably on a test branch first!"