Reputation: 335
So I forgot to add my name and email to git config and after I pushed my changes I got a default name. It basically looks like this:
How am I supposed to change the name and email of the second commit on this list (top to bottom) without affecting the other things or messing up branches?
EDIT: I forgot to add that I'm the only one working on this branch feature.
Upvotes: 0
Views: 108
Reputation: 43700
You can rebase your branch which would let you "redo" the commit and get it to have your name. Then you would need to force push the changes to the remote.
The commands to do this are:
git rebase -i <SHA before the commit with the default name>
You will get the list of commits, for the one with the default name specify that you want to "reword" it. Save the commit message and your history will be up to date.
In order to update the remote, you would do git push -f
. This tells git that your changes should overwrite what is on the remote repository.
THIS IS NOT RECOMMENDED
Doing the above is changing history and will cause problems if other people are also working on this branch. They will have issues when they try to update the branch with your changes. If you are the only person dealing with this branch it isn't a problem.
If multiple people are working on the branch, just leave the commit alone. You don't want to rewrite history once you have pushed.
Upvotes: 2
Reputation: 30212
You actually can't without modifying anything. Modifying whatever information from a revision (with an amend, for example) will create a totally different revision. You could do this:
git checkout my-branch~2 # two revisions back from the branch tip
git commit --amend --author "Foo Bar <[email protected]>"
git cherry-pick my-branch~2..my-branch # reapply revisions 3 and 4
git branch -f my-branch # set my-branch over here
But from the point you amended, you are creating completely new revisions that are unrelated (in terms of history) to the original ones. Will require a force push on the remote to replace the branch, will require other developers to be aware of this change so they can rebase if they are already working on top of this branch. Not particularly painful, anyway.... business as usual, if you ask me.
Upvotes: 1