我在一个个人项目中使用Mercurial,每次我想向服务器推送一些东西时,我都要输入我的用户名和密码。

我尝试将以下内容添加到主目录中的.hgrc文件中,但它似乎完全被忽略了。

[ui]
username = MY_USER_NAME
password = MY_PASSWORD

如何正确地做到这一点?


当前回答

没人提到密匙环扩展。它会将用户名和密码保存到系统密匙环中,这比上面提到的将密码存储在静态文件中要安全得多。执行下面的步骤,您就可以开始了。我用了大约2分钟就在Ubuntu上安装并运行了它。

>> sudo apt-get install python-pip
>> sudo pip install keyring
>> sudo pip install mercurial_keyring

**Edit your .hgrc file to include the extension**
[extensions]
mercurial_keyring = 

https://www.mercurial-scm.org/wiki/KeyringExtension

其他回答

一个简单的破解方法是在项目的。hg/hgrc文件中添加用户名和密码到推送url:

[paths]
default = http://username:password@mydomain.com/myproject

(注意,通过这种方式,您可以以纯文本的形式存储密码)

如果您在同一个域下处理多个项目,您可能希望在~/中添加一个重写规则。HGRC文件,以避免对所有项目重复此操作:

[rewrite]
http.//mydomain.com = http://username:password@mydomain.com

同样,由于密码是以纯文本形式存储的,所以我通常只存储我的用户名。

如果你在Gnome下工作,我在这里解释如何集成Mercurial和Gnome Keyring:

http://aloiroberto.wordpress.com/2009/09/16/mercurial-gnome-keyring-integration/

有三种方法:使用.hgrc文件,使用ssh或使用keyring扩展名

1. 不安全的方式-更新您的~/。hgrc文件

适合我的格式(在我的~/。HGRC文件)是这样的

[ui]
username=Chris McCauley <chris.mccauley@mydomain.com>

[auth]
repo.prefix = https://server/repo_path
repo.username = username
repo.password = password

You can configure as many repos as you want by adding more triplets of prefix,username, password by prepending a unique tag. This only works in Mercurial 1.3 and obviously your username and password are in plain text - not good. 2. The secure way - Use SSH to AVOID using passwords Mercurial fully supports SSH so we can take advantage of SSH's ability to log into a server without a password - you do a once off configuration to provide a self-generated certificate. This is by far the safest way to do what you want. You can find more information on configuring passwordless login here 3. The keyring Extension If you want a secure option, but aren't familiar with SSH, why not try this? From the docs ... The extension prompts for the HTTP password on the first pull/push to/from given remote repository (just like it is done by default), but saves the password (keyed by the combination of username and remote repository url) in the password database. On the next run it checks for the username in .hg/hgrc, then for suitable password in the password database, and uses those credentials if found. There is more detailed information here

在Mac OSX上使用MacPorts安装mercural_keyring:

sudo port install py-keyring
sudo port install py-mercurial_keyring

在~/.hgrc中添加以下内容:

# Add your username if you haven't already done so.
[ui]
username = email@address.com

[extensions]
mercurial_keyring =

上面没有人向新手解释/澄清术语。他们被这些术语弄糊涂了

.hg/hgrc——此文件用于存储库,在本地/工作空间位置/实际存储库的.hg文件夹中。

~ /。HGRC——这个文件与下面的文件不同。该文件位于~或主目录。

myremote.xxxx =… bb.xxxx =……

This is one of the lines under [auth] section/directive, while using mercurial keyring extension. Make sure the server name you put there, matches with what you use while doing "hg clone" otherwise keyring will say, user not found. bb or myremote in the line below, are "alias name" that you MUST give while doing "hg clone http:/.../../repo1 bb or myremote" otherwise, it wont work or you have to make sure your local repository's .hg/hgrc file contain same alias, ie (what you gave while doing hg clone .. as last parameter).

PS以下链接为清晰的细节,抱歉太快写语法。

https://stackoverflow.com/questions/14267873/mercurial-hg-no-changes-found-cant-hg-push-out/14269997#14269997 http://www.linuxquestions.org/questions/showthread.php?p=4867412#post4867412 https://stackoverflow.com/questions/12503421/hg-push-error-and-username-not-specified-in-hg-hgrc-keyring-will-not-be-used/14270602#14270602 —Windows LDAP—组用户认证—Mercurial

如果在~/。hgrc (Linux/Unix中用户的主目录)或Windows中的mercury .ini在用户的主目录中,包含,下面的行,如果你做

`"hg clone http://.../.../reponame myremote"`

,那么在每个HTTP回收链接中,用户凭证的提示永远不会超过一次。在~ /。HGRC下的[扩展]一行“mercural_keyring =”或“hgeext。mercural_keyring = /path/to/your/ mercural_keyring .py" ..这里应该有一条线。

[auth]
myremote.schemes = http https
myremote.prefix = thsusncdnvm99/hg
myremote.username = c123456

我试图找出如何设置前缀属性,以便用户可以克隆或执行任何Hg操作,没有用户名/密码提示,而不用担心他在http://..../中提到的…当使用Hg repo链接时,为服务器名。它可以是IP、服务器名或服务器的FQDN

如果您正在使用TortoiseHg,您必须执行附件屏幕截图中显示的这三个步骤,这将为您正在使用的特定存储库添加您的凭据。

要添加全局设置,您可以访问文件C:\users\user.name\ mercury .ini并添加section

[auth]
bb.prefix=https://bitbucket.org/zambezia/packagemanager
bb.username = $username
bb.password = $password

希望这能有所帮助。