2

I noticed something which might be beneficial to me, but i was not sure what was going on with my version. How to change the commit author for one specific commit?

So, I saw a great 1-liner which would say, start at the first commit, and ammend all authors to XXX. I thought it was going to work, but when I pushed, it said multple heads. I pulled and pushed and noticed that when looking at the repo history, I saw a bunch files now saying:

Authored by X, Comitted by Y.

I was hoping to strip and update all emails accordingly for some repos with relevant or correct spellings etc.

My desired end state is to completely override and replace it, so it never shows up in the git history at all. It seems that my way is not quite correct.

The reason is that I have broken or Invalid Authors/Committers, and emails etc. I want to be able to update them, and eventually set up a system to do auto-email routing to colleagues who no longer work at our company.

Fallenreaper
  • 10,222
  • 12
  • 66
  • 129
  • Why are you trying to rewrite the history of a GitHub repo? This is generally a bad thing to do. – Tim Biegeleisen Nov 13 '18 at 02:25
  • I was working on some of my repos, and i noticed wrong, broken, or incorrect Author names, emails etc... So if i can figure out how to properly accomplish this, I could expand it to not just replace entirely, but tweaks etc. It seems like it would laterally help my work as well, as I have different users for different teams, and I want to eventually scan and update those as well – Fallenreaper Nov 13 '18 at 02:29
  • @TimBiegeleisen I also noticed that GIT has an example of this as well https://help.github.com/articles/changing-author-info/#platform-mac but it seems that even after I make the adjustments, I still dont see it work explicitly as designed, given my old email was "1234567" – Fallenreaper Nov 13 '18 at 03:19
  • @Fallenreaper, have you looked into `git-filter-branch`? This answer looks to be up your alley - https://stackoverflow.com/questions/4493936/could-i-change-my-name-and-surname-in-all-previous-commits#4494037 – miqh Nov 13 '18 at 03:21
  • @miqh I was looking into it, and with github help section, they were also listing that as an option. I was looking at the code snippet from your link: `git filter-branch --commit-filter 'if [ "$GIT_COMMITTER_EMAIL” = “1234567” ]; then export GIT_AUTHOR_NAME=“MYNAME”; export GIT_AUTHOR_EMAIL=TEST@EMAIL.COM; fi; git commit-tree "$@"'` but it gives me an unexpected EOF. – Fallenreaper Nov 13 '18 at 04:09

1 Answers1

1

You should:

  • apply a filter-branch (as in here) changing both the author and committer.
    That will avoid seeing "authored by X, committed by Y"

  • git push --force at the end, in order to overwrite the remote repo history (make sure to warn any collaborator on that repo first)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This works perfectly. I was having issues and tried a bunch of different options. I am not sure why it is suddenly working today, but either way, i am happy. – Fallenreaper Nov 13 '18 at 23:08