Last active
July 16, 2019 07:09
-
-
Save toddsby/55fda78bd089c28aeb8061f2bc12592c to your computer and use it in GitHub Desktop.
bash script git filter-branch change committer and author email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
echo "CHOOSE OPTION" | |
echo "[0] HEAD / [1] BRANCH NAME" | |
read REPLACE_EMAIL_OPTION | |
if [[ $REPLACE_EMAIL_OPTION = 0 ]] | |
then | |
GIT_BRANCH="HEAD" | |
else | |
echo "PROVIDE BRANCH NAME:" | |
read GIT_BRANCH | |
fi | |
echo "$REPLACE_EMAIL_OPTION" | |
echo "$GIT_BRANCH" | |
git filter-branch -f --env-filter ' | |
# replace domain.com with your <domain> | |
GIT_EMAIL_PATTERN="^(.*)@.*\.domain\.com$" | |
if [[ $GIT_COMMITTER_EMAIL =~ $GIT_EMAIL_PATTERN ]] || [[ $GIT_AUTHOR_EMAIL =~ $GIT_EMAIL_PATTERN ]]; | |
then | |
echo "WE HAVE A MATCH" | |
export GIT_COMMITTER_EMAIL="${BASH_REMATCH[1]}@domain.com" | |
export GIT_AUTHOR_EMAIL="${BASH_REMATCH[1]}@domain.com" | |
echo "$GIT_COMMITTER_EMAIL" | |
else | |
echo "NOPE" | |
fi | |
#echo "${BASH_REMATCH[0]}" | |
#echo "$GIT_COMMITTER_EMAIL" | |
' $GIT_BRANCH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if RegEx matches, then the capture groups are available in
BASH_REMATCH[1]
,BASH_REMATCH[2]
, etcread REPLACE_EMAIL_OPTION
read in a bash script waits for user input
$GIT_BRANCH
git filter-branch requires the final param be the branch to apply the history rewrite, or HEAD for convenience