سؤال

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?

هل كانت مفيدة؟

المحلول

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?

نصائح أخرى

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

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top