Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
873 views
in Technique[技术] by (71.8m points)

git - How to change commit author for multiple commits using filter branch?

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 git mailmap for the exact syntax of that mapping file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...