HgGit: “invalid-email-address” at GitHub

风格不统一 提交于 2019-12-07 01:09:16

问题


I started to use HgGit extension for mercurial to have copy of repository at GitHub. Almost everything is working well, but in commits information at GitHub I see invalid-email-address (author) instead of my username. Is there a way to show username correctly in this case?


回答1:


A username in Mercurial is usually of the form:

Name <email@domain.com>

Git also is usually set up with a name and an e-mail address for the user.

You probably need to specify an e-mail address in your username in your Mercurial config so that the username in the commits works correctly on github.

This username is not required to be the same as your username at any particular website, it's for commit information. If it were required to be the same, how would you ever be able to push changesets done by someone else?

For example, my bitbucket username is different than my Mercurial username on my commits, and the way I keep my bitbucket username and password out of the bitbucket paths in the repo's hgrc is to use the [auth] section of my user .hgrc/Mercurial.ini:

[auth]
bb.prefix = bitbucket.org
bb.schemes = https
bb.username = myBBusername
bb.password = myBBpassword

Putting the password here is optional (you'll be prompted), but there are more secure alternatives for storing it, such as the keyring extension.

However, it's a bit late to change the username on existing changesets (you'd have to re-write the repo's entire history).




回答2:


In order to fix the "invalid-email-address" issue you have to find old "git author names" in commits and set new names and email addresses of the "Author" and "Committer" for the commits before you push newly converted repository to GutHub.

This fix (search and replace...) is done using "git filter-branch" command. You may see ready to use example here: (now it's dead?!) Mercurial to Git, solving "invalid-email-address"

[Edited:] As the link above is dead now, I provide my example of the "fix-user-email.sh" file below. As yo may see, here two variants of an author name are being translated into the same valid GIT name/email pair:

git filter-branch --env-filter '

an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"

if [ "$GIT_AUTHOR_NAME" = "peter.pen" ]
then
    cn="peterpen"
    cm="peterpen@example.com"
    an="peterpen"
    am="peterpen@example.com"
fi
if [ "$GIT_AUTHOR_NAME" = "peterpen" ]
then
    cn="peterpen"
    cm="peterpen@example.com"
    an="peterpen"
    am="peterpen@example.com"
fi

export GIT_AUTHOR_NAME="$an"
export GIT_AUTHOR_EMAIL="$am"
export GIT_COMMITTER_NAME="$cn"
export GIT_COMMITTER_EMAIL="$cm"
'

I personally executed commands from the above mentioned page step by step in cygwin bash window (actually I ran/modified/re-ran a script in order to simplify my life, of course :-) ) and checked results using GIT-GUI...

When you are ready to test repository on GitHub,

  1. Create new repository at GitHub and do nothing with it!
  2. Push converted repo to the Git Hub. If something is not good yet, delete the repo from GitHub and create repo with the same name again...


来源:https://stackoverflow.com/questions/6942196/hggit-invalid-email-address-at-github

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!