When I started using git I just did a git init and started calling add and commit. Now I am starting to pay attention and I can see that my commits are showing up as cowens@localmachine, rather than the address I want. It appears as if setting GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL will do what I want, but I still have those old commits with the wrong email address/name. How can I correct the old commits?
| |||
|
feedback
|
|
You can go back and fix all your commits with a single call to git filter-branch. This has the same effect as rebase, but you only need to do one command to fix all your history, instead of fixing each commit individually. I think you could fix all the wrong emails with this line:
(Warning: that above script is untested) More information is available from the git docs | |||||||||||||
feedback
|
|
Git's filter-branch command is powerful, but it's horribly unwieldy to use for anything non-trivial, like for example, if you have more than one author to correct. Here's an alternative I found useful, which uses the .mailmap feature described in the git-shortlog manpage. This provides an author mapping mechanism we can use with git log's formatting facility. We can use it to generate the commands to pick and amend amend a named sequence of commits. For example, suppose you want to correct the authorship on a branch $BRANCH, starting at a commit $START. You need to create a .mailmap file in the top directory of your repository which maps the existing author names to he correct ones. You can get a list of the existing author names with:
You need to end up with a .mailmap file like this (say):
Now you can use git log's formatting feature to generate the commands to rewrite $BRANCH as $BRANCH2.
The first command creates a new empty branch sprouting from the commit $START. For each commit between $START and then end of $BRANCH, the second command cherry picks the original commit on to the end of the current branch $BRANCH2, and amends it to set the author correctly. This is also generally applicable - put this in your ~/.gitconfig:
So when you need to correct authors, now you just then need to generate a .mapfile and do:
The original branch ref can be reassigned to the new one, and the new one deleted:
| ||||
|
feedback
|
|
Combining the answer from How do I fix the metainformation on the first commit in git?
| |||
|
feedback
|
|
You need to use git rebase. Here is a tutorial: | |||
|
feedback
|
|
To follow jedberg's answer: You can use | |||
|
feedback
|