7

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.

Community
  • 1
  • 1
Hinton
  • 2,111
  • 2
  • 25
  • 30
  • Duplicate of [What's a "fast-forward" in Git?](http://stackoverflow.com/questions/4684352/whats-a-fast-forward-in-git) –  May 18 '14 at 16:58
  • How is that a duplicate? That the answer to the question is related in some ways does not mean that the question is the same, but differently phrased. – Hinton May 19 '14 at 12:00
  • I consider this a duplicate. Not only are the solutions essentially identical, i.e. force push, but that appears to have been your only problem, after successfully rewriting your history. If anyone disagrees, they can't just reopen your question. –  May 19 '14 at 16:38
  • Cupcake, did you even read my response? Do you have to say anything to the fact that just because the solutions are related, this does not make the question the same? And what to you mean by "if anyone disagrees, they can't (sic) just reopen the question"? – Hinton May 19 '14 at 16:56
  • Regarding "they can't just reopen your question", that was a typo, it was supposed to say "they can just reopen your question". –  May 19 '14 at 16:57
  • So because you misunderstood what it means to have a push rejected as a non-fast-forward, you ended up pulling and causing a bunch of conflicts instead, and then you didn't know how to delete branches and reset branches to previous states, correct? Seems to me your primary problem was still the fact that you didn't understand the difference between normal pushing and force pushing. As for the problem of causing invalid merges with conflicts, just abort the merge and/or do hard resets back to your previous commits. –  May 19 '14 at 17:02
  • Correct, that's an appropriate analysis of the question, and could be turned into an answer. Saying that the questions are the same is like holding forth that since pi is the answer to both "4*int(from 0 to 1) of sqrt(1-x²) dx?" and "what's the relation of circumference and diameter of a circle?", the questions must be the same. – Hinton May 19 '14 at 17:13

2 Answers2

5

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.

Jeremy
  • 1
  • 77
  • 324
  • 346
  • OK -- that worked as far as finally removed the author name. Do you perhaps also have a clue on how to remove all these branches that I accidentally created? – Hinton Aug 28 '11 at 13:12
  • Also, make sure you tell everyone they need to "refetch" the repo. – Andy Aug 28 '11 at 13:13
  • @Andi it's a "quasi-private" repo still (meaning I'm the only committer ^^)... I wouldn't have done it in another case anyway. – Hinton Aug 28 '11 at 13:16
  • @Hinton: I'm not entirely sure (I know from my own experience if you don't know what you're doing, you can make a horrible and difficult-to-resolve mess), but I've added a suggestion to the answer. – Jeremy Aug 28 '11 at 13:16
1

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

Philip Oakley
  • 11,745
  • 8
  • 42
  • 63