11

I am using this script found at this link to edit author info across all commits.

#!/bin/sh

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

However, I am getting the following error(warning?):

Cannot create a new backup.
A previous backup already exists in refs/original/
Force overwriting the backup with -f

I checked the log too. The author info didn't change. What am I doing wrong here?

Update: As mentioned by @elpiekay, the -f flag made the script work.

But can anyone explain the error log itself? Why does it mention about backup ? I never made any backup before (unsure what backup is being referred in the error log)

Saurabh P Bhandari
  • 6,014
  • 1
  • 19
  • 50
  • 1
    Did you try `-f` as the error log suggested? – ElpieKay Oct 07 '19 at 03:38
  • @ElpieKay, I tried it now and it works – Saurabh P Bhandari Oct 07 '19 at 03:55
  • 2
    Every time you run `git filter-branch` successfully, one or more refs are rewritten and backups are created for each of them. When you run it again, the backups will be overwritten, which means the previous backups will seem lost. Although it's still possible to find them back, it's just troublesome. The command fails unless the user specifically uses `-f` to instruct it to overwrite the previous backups. – ElpieKay Oct 07 '19 at 04:07
  • @ElpieKay, ohk , I checked my reflog and it had an entry of filter-branch before executing this script, so that's where the previous backup came from, thanks for clearing it up, you might as well answer the question :) – Saurabh P Bhandari Oct 07 '19 at 04:11

1 Answers1

35

Actually, a better practice is to:

You can instead used right now its possible successor: newren/git-filter-repo (in Python), and its example section:

cd repo
git filter-repo --mailmap my-mailmap

with my-mailmap:

Correct Name <correct@email.com> <old@email.com>

That would replace the author name and email of any commit done by anyone with <old@email.com>

See documentation on gitmailmap for the exact syntax of that mapping file.

noritada
  • 7
  • 3
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the answer, I would like to give some background on the repository, I have actually exported a unity project from cloud so the reflog on the exported repo indicated two operations: clone(from their cloud storage) and filter-branch – Saurabh P Bhandari Oct 07 '19 at 05:41
  • @SaurabhPBhandari Those are two legitimate steps, except the new tool (`git filter-repo`) replacing `git filter-branch` would perform the filtering much more efficiently. – VonC Oct 07 '19 at 06:14