10

I have rebased a branch and now all its commits have committer section which I would like to remove completely (not just changing it's fields). Is it possible without losing the original author info?

John Vandenberg
  • 474
  • 6
  • 16
Andrei
  • 10,918
  • 12
  • 76
  • 110
  • 2
    Every commit have a committer header as well as an author header. You may see only one of them when both are identical with some clients, though. – Matthieu Moy May 29 '18 at 13:38

2 Answers2

16

Thanks to @sergej and GitHub, I got committer info removed with

git filter-branch --env-filter '
if [ "$GIT_COMMITTER_EMAIL" != "$GIT_AUTHOR_EMAIL" ]; then
  export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
  export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
  export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
fi
' --tag-name-filter cat -- --branches --tags
Andrei
  • 10,918
  • 12
  • 76
  • 110
5

You have to rewrite the history.

GitHub has a script that does that, see Changing author info.

It should be straight forward to adopt it to your needs:

#!/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
sergej
  • 17,147
  • 6
  • 52
  • 89
  • Thanks. Do I understand correctly, that if `GIT_COMMITTER_NAME` etc match `GIT_AUTHOR_NAME` etc, it will be considered as removed? – Andrei Oct 05 '15 at 08:42
  • Yeah, just tested, seems to be the case – Andrei Oct 05 '15 at 08:56
  • doesn't work. Creates another branch with the old wrong commits. – Liquid Core May 29 '18 at 13:18
  • @LiquidCore have you down-voted this answer? It might not work for [you question](https://stackoverflow.com/q/50583090/2020827), but it helped here. – sergej May 29 '18 at 13:22
  • 4
    For the benefit of anyone confused by this exchange, Liquidcore is upset because the answer didn't point out that `filter-branch` creates back up refs, and this confused them into thinking the command hand't worked. Rather than admit to having been in error, they appear to have doubled down by standing behind an inappropriate down-vote, when in fact the answer worked fine. – Mark Adelsberger May 29 '18 at 14:01