Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change author name of previous commits: Fast-forward pushes rejected

Tags:

git

github

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:

  1. http://help.github.com/change-author-info/

  2. Delete commits from a branch in Git

  3. How to remove selected commit log entries from a Git repository while keeping their changes?

  4. Change the author and committer name and e-mail of multiple commits in Git

  5. Change commit author at one specific commit

  6. Change first commit of project with Git?

  7. 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.

like image 579
Hinton Avatar asked Aug 28 '11 13:08

Hinton


2 Answers

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.

like image 109
Jeremy Avatar answered Oct 21 '22 20:10

Jeremy


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 ;-)

like image 25
Philip Oakley Avatar answered Oct 21 '22 19:10

Philip Oakley