0

I have a git repo, where I committed from different computers and so I ended up showing as 2 different contributors, but in fact it is one user - me. How I can unite these users into one?

Sergiu Dumitriu
  • 11,455
  • 3
  • 39
  • 62
Gulaev Valentin
  • 575
  • 1
  • 7
  • 19

3 Answers3

2

You have to set your username and email to be the same in both the machines:

git config --global user.name <name>
git config --global user.email <email>

If you want to change existing commits, be warned that you will be rewriting history.

You can refer to this answer: How do I rewrite committer names in a git repository?

Community
  • 1
  • 1
manojlds
  • 290,304
  • 63
  • 469
  • 417
  • What do with existing commits? – Gulaev Valentin Jan 06 '13 at 10:48
  • @GulaevValentin - It is best to leave them alone. But, if you want to change - http://stackoverflow.com/questions/1566809/how-do-i-rewrite-committer-names-in-a-git-repository – manojlds Jan 06 '13 at 10:57
  • 1
    Use a `.mailmap` file as suggested by nulltoken. It is designed for exactly this purpose where folk change their email signature over time and location. – Philip Oakley Jan 06 '13 at 16:36
  • @PhilipOakley - I don't think that is applicable here. The OP, being a newb, did not set user and email and it was different in the two machines ( the default ones with hostname etc). The OP does not have a requirement to add two mail ids ( and in this case, its not even two valid email ids). Of course, this is based on what I understand. – manojlds Jan 06 '13 at 16:44
  • @PhilipOakley it applicable in my case, many thanks for answer. – Gulaev Valentin Jan 22 '13 at 04:37
1

@SergiuDumitriu is right about adding all your emails to your account at https://github.com/settings/emails. This way all your committed work (from different emails) will be linked to your GitHub account and aggregated in the Graphs section of each of the repositories you've contributed to.

However, in order to also make this happening on your local repository on your computer, you will have to commit a .mailmap file to the root of your repository which will link your emails all together. Once can find more information about this git feature and the file format in the git shortlog documentation.

This way running $ git shortlog -s -n will correctly aggregate all of your identities.

Community
  • 1
  • 1
nulltoken
  • 64,429
  • 20
  • 138
  • 130
0

If all you care about is to get all commits linked to your GitHub account, then it's enough to add both email addresses to your account.

If you really want to modify all the existing commits, don't do that unless the code hasn't been really used by anyone else, since you're going to rewrite every commit, the entire history in your repository.

If you still want to do that, you should use git-filter-branch --env-filter, as seen in this answer.

Community
  • 1
  • 1
Sergiu Dumitriu
  • 11,455
  • 3
  • 39
  • 62