termblack

git: history reclaim/redo/fix

The standard instructions confused me, so here they are simplified with better references to account and repo specific variables.  (taken almost entirely from github instructions)

–Open a terminal

//write down the old email shown in git log
git log

 

–CD into your current repo

//the following will create a temp sub folder containing a packed version of the repo
git clone --bare https://github.com/YOURUSERNAME/THISREPONAME.git
//now cd into the new temp directory
cd THISREPONAME.git

 

–Create this bash script:

#!/bin/sh
#replace the 3 lines for old, correct name , correct email
git filter-branch --env-filter '

OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

 

–Execute the bash script in the new temp folder

–Replace entire remote with entire local

git push --force --tags origin 'refs/heads/*'

 

–Delete the temp folder

cd .. //(into main folder)
rm -rf THISREPONAME.git

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>