Course Tonight

Course Tonight

Did You Know?

You can create any type of product documentation with Docy

Chapter 35: Rewriting history with filter-branch

Estimated reading: 1 minute 6 views

Section 35.1: Changing the author of commits

You can use an environment filter to change the author of commits. Just modify and export $GIT_AUTHOR_NAME in the script to change who authored the commit.

Create a file filter.sh with contents like so:

if [ "$GIT_AUTHOR_NAME" = "Author to Change From" ]
then
export GIT_AUTHOR_NAME="Author to Change To"
export GIT_AUTHOR_EMAIL="email.to.change.to@example.com"
fi

Then run filter-branch from the command line:

chmod +x ./filter.sh
git filter-branch --env-filter ./filter.sh

Section 35.2: Setting git committer equal to commit author

This command, given a commit range commit1..commit2, rewrites history so that git commit author becomes also git committer:

git filter-branch -f --commit-filter \
'export GIT_COMMITTER_NAME=\"$GIT_AUTHOR_NAME\";
export GIT_COMMITTER_EMAIL=\"$GIT_AUTHOR_EMAIL\";
export GIT_COMMITTER_DATE=\"$GIT_AUTHOR_DATE\";
git commit-tree $@' \
-- commit1..commit2

Leave a Comment

Share this Doc

Chapter 35: Rewriting history with filter-branch

Or copy link

CONTENTS