Jack Slingerland
Jack Slingerland

Reputation: 2811

Git filter-branch not rewriting all history

I'm trying to re-write a repo's history using:

git filter-branch -f --env-filter '
        an="$GIT_AUTHOR_NAME"
        am="$GIT_AUTHOR_EMAIL"
        cn="$GIT_COMMITTER_NAME"
        cm="$GIT_COMMITTER_EMAIL"

        if [[ "$GIT_COMMITTER_EMAIL" = jacks* ]]
        then
            cn="Jack Slingerland"
            cm="[email protected]"
            an="Jack Slingerland"
            am="[email protected]"

        fi

        if [[ "$GIT_AUTHOR_EMAIL" = jacks* ]]
        then
            cn="Jack Slingerland"
            cm="[email protected]"
            an="Jack Slingerland"
            am="[email protected]"
        fi

        export GIT_AUTHOR_NAME="$an"
        export GIT_AUTHOR_EMAIL="$am"
        export GIT_COMMITTER_NAME="$cn"
        export GIT_COMMITTER_EMAIL="$cm"'
 -- --all

The command runs fine, and rewrites the author as specified. The problem is that it seems to miss some entries in the history. I think it's happening when changes made in a branch were merged in, but I'm not sure.

Note: This is an SVN repository that was imported into Git using Git+SVN.

Upvotes: 1

Views: 470

Answers (1)

James
James

Reputation: 1804

I don't think your conditionals are checking what you want. Shouldn't:

if [[ "$GIT_AUTHOR_EMAIL" = jacks* ]]

be

if [[ "$GIT_AUTHOR_EMAIL" =~ "jacks.*" ]]

Note: this will only work in Bash 3.0 or higher. Otherwise I think you'll need to use grep or sed external commands as part of your conditional checks.

Also, I think you will only want to change the commiter when the commiter's email isn't Jack's and vice versa for the author. So make sure you take out your an and am assignments in your comitter email check and make the similar fix to your author email check.

Upvotes: 1

Related Questions