I recently opened a repo on GitHub. I'm new to Git. As usual with newcomers, I committed using the default name and email, which I, in the best noob tradition, discovered five commits too late. Now the fun starts, cause I started to search for info on how to change the author & committer name of these commits. Fine. I basically found the following info and a lot of copies:
http://help.github.com/change-author-info/
Delete commits from a branch in Git
How to remove selected commit log entries from a Git repository while keeping their changes?
Change the author and committer name and e-mail of multiple commits in Git
Change commit author at one specific commit
Change first commit of project with Git?
Could I change my name and surname in all previous commits?
The problem does not seem to be uncommon. I can only say that none of the solutions worked. Half of them are variations of the same git filter-branch -f --env-filter
script. I tried to work on that script multiple times. The problem is that after applying the script, I cannot push. "Fast-forward pushes rejected" or something like that. Fine, the only way to go on is to pull. After pulling, all the old info is there again + a new branch with the new info. I'm already sitting here with four branches, merged in the most egregious ways, all containing the same info with different author names, including the one I wanted to delete.
OK to cut it short, I also tried to delete selected commits, which generates hair-raising conflicts that I am unable to resolve (how???), and to squash some of the commits into newer ones with the correct author information, which results in the current project state being wrecked. Even better, I get a segmentation fault sometimes after executing git rebase -i
, which I'm informed here: http://lists-archives.org/git/729800-rebase-i-segmentation-fault-and-another-problem.html is completely logical. The only thing that (thankfully) works is git rebase --abort
, which saved my ass multiple times.
I hope my frustration does not repel, but instead amuse you and stimulate you to help me. I'd like:
To remove said author info finally
Bonus: To get rid of all the branches containing the same information.
But I'd be happy with the first one too, if the hurdle of deleting past branches without wrecking the current state is too much for a git newcomer. Thanks in advance.
The problem is that after applying the script, I cannot push. "Fast-forward pushes rejected" or something like that.
This problem cannot be avoided if you're trying to modify the history. Git's rejecting the push because it causes data to be lost; in this case that data is the old authors. You just need to git push
with the --force
flag to tell it you're sure of what you're doing.
Messes in Git can be a pain to resolve. If master
is a mess, I usually just move back through the history with git checkout HEAD~
until I get back to a time when things weren't terrible. I then git branch --force master
to reset master
to that point. Finally I delete all of the messy branches with git branch -D badBranch
.
Be careful.
If no-one is yet following your repo, then simply amend you local repo and force the push to GitHub. Accept any embarrassment. I've been (re)building a repo for weeks in a similar vein.
It's more tricky if it is a student project and the lecturer has already pulled it - just to make you appreciate the value of good admin ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With