This gist makes it extremely easy to replace git author information by rewriting your git commit history.
Note
We make use of the git-filter-repo
dependency because git filter-branch
has a plethora of pitfalls.
Warning
- Every commit made by
$GIT_OLD_NAME
will be replaced with$GIT_NEW_NAME
. - Every commit made by
$GIT_OLD_EMAIL
will be replaced with$GIT_NEW_EMAIL
.
Caution
This is a destructive action! Git commit history will be permanently rewritten.
Install the required dependecies:
apt install git-filter-repo
Create a file named replace-git-author-information.env
with the contents:
GIT_CLONE_URL='https://code.neureka.dev/components/docker.git'
GIT_REPO_NAME=$(cut -d '.' -f1 <<< $(cut -d '/' -f5 <<< $GIT_CLONE_URL) )
GIT_OLD_NAME=''
GIT_OLD_EMAIL=''
GIT_NEW_NAME=''
GIT_NEW_EMAIL=''
Create a file named replace-git-author-information
with the contents:
#!/bin/bash
if [ ! -f replace-git-author-information.env ]; then
echo "[ERROR]: Please create a 'replace-git-author-information.env' file!"
exit 1
fi
source replace-git-author-information.env
# TODO: Check Vars
# Loop list of repos
cd /tmp
git clone "$GIT_CLONE_URL"
cd "$GIT_REPO_NAME"
git-filter-repo --name-callback "return name.replace(b'$GIT_OLD_NAME', b'$GIT_NEW_NAME')" --email-callback "return email.replace(b'$GIT_OLD_EMAIL', b'$GIT_NEW_EMAIL')"
git push --set-upstream "$GIT_CLONE_URL" main --force
cd -
rm -rf "$GIT_REPO_NAME"