1

I have been following various guides on how to update the authors for commits in Git, but I haven't managed to update the Author for a branch that was previously merged.

Here is what the commit history looks like:

A - B - C - D - E - F - G
         \ 1 - 2 - 3 - 4 - 5 - 6... 

So far I've managed to re-write the authors of the top branch. Although it's not easy to find: In something like Gitlab if you view commit C and then follow the links to the parent commit a few times you will eventually find commits where the Author hasn't updated in commits 3, 4, 5 etc.

How can I update these?

The script I ran to update most of the commits was:

git filter-branch -f --commit-filter '
        if [ "$GIT_AUTHOR_NAME" = "OLD-USER" ];
        then
                GIT_COMMITTER_NAME="NEW-USER";
                GIT_AUTHOR_NAME="NEW-USER";
                GIT_COMMITTER_EMAIL="NEW-EMAIL";
                GIT_AUTHOR_EMAIL="NEW-EMAIL";
                git commit-tree "$@";
        else
                git commit-tree "$@";
        fi' HEAD

Edit

Thanks to Greg Hewgill's answer, the below script fixed it

git filter-branch -f --commit-filter '
        if [ "$GIT_AUTHOR_NAME" = "OLD-USER" ];
        then
                GIT_COMMITTER_NAME="NEW-USER";
                GIT_AUTHOR_NAME="NEW-USER";
                GIT_COMMITTER_EMAIL="NEW-EMAIL";
                GIT_AUTHOR_EMAIL="NEW-EMAIL";
                git commit-tree "$@";
        else
                git commit-tree "$@";
        fi' -- --all
Baa
  • 438
  • 3
  • 7
  • 22

1 Answers1

1

By using HEAD at the end of your command line, you have only changed the history for the current branch. To change the history for all branches, replace HEAD with -- --all.

From the git filter-branch documentation:

<rev-list options>…​

Arguments for git rev-list. All positive refs included by these options are rewritten. You may also specify options such as --all, but you must use -- to separate them from the git filter-branch options.

Community
  • 1
  • 1
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285