Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jasonnicholson/ee9f3255e1e0abb9e1527e9f3e36aa82 to your computer and use it in GitHub Desktop.
Save jasonnicholson/ee9f3255e1e0abb9e1527e9f3e36aa82 to your computer and use it in GitHub Desktop.
Installing git filter-repo, rewriting repo

Objective

Rewrite a repo removing any traces of personal email address such as commit email, email, and sign-off.

Details

git-filter-branch is slow. Also, it is known to be problematic. I have experienced the slow but didn't run into the problematic part. Instead, I just went for using git-filter-repo.

git-filter-repo was not straight forward to get installed on Windows. I tried several ways to get it working that I won't explain here. What worked was installing Anaconda and then pip installing git-filter-branch.

In an Anaconda prompt, I typed

pip install git-filter-repo

GIT was already installed, version 2.30.02.windows.2. Initially, I was working with getting git-filter-branch in an Anaconda prompt since the python path was already update. I struggled with the mixing of escaping text strings at the command prompt because of mixing " and '. So I decided to switch into git bash. This meant I had to update the path in git bash. This takes a while because you have to convert a windows path to a valid bash path. This is the line of code I needed in git bash:

export PATH=/c/Users/jason/Programs/Anaconda3:/c/Users/jason/Programs/Anaconda3/Library/mingw-w64/bin:/c/Users/jason/Programs/Anaconda3/Library/bin:/c/Users/jason/Programs/Anaconda3/Scripts:/c/Users/jason/Programs/Anaconda3/condabin:$PATH

Then, I could use git-filter-branch. I needed to use the mailmap, message-callback, and replace-refs features; you can find these features in the git-filter-branch help. The full command was like this:

git filter-repo --force --mailmap ../mailmap.txt --message-callback 'return message.replace(b"oldEmail@something.com", b"newEmail@something.com")' --replace-refs delete-no-add

I used mailmap to map an old email to a new one like with the file mailmap.txt as shown below:

New Name <newEmail@something.com> Old Name <oldEmail@something.com>
<newEmail@something.com> <oldEmail2@something.com>

Then, I needed to use the message-callback to replace an old email that was in the signed-off-by in commits. This is where the single and double quotes were giving me trouble before.

I used the --replace-refs because it didn't add replace/hash to the commit hash. See the git-filter-repo help. I just know it worked the way I wanted it. I don't fully understand this part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment