快速入门

(参见 UnderstandingMercurialTutorial and QuickStart2)

1. 设置用户名

默认情况下,Mercurial 使用 user@localhost 格式作为commits时的用户名。这样做通常无任何意义。您最好能在~/.hgrc(在Windows系统中,是%USERPROFILE%\Mercurial.ini)中加入合适的email地址。如下所示:

[ui]
username = John Doe <john@example.com>

2. 在现有的 Mercurial 项目中工作

如果你有一个URL支持的项目repository (例如 http://selenic.com/hg), 你可以用下面的方法抓取一个副本:

$ hg clone http://selenic.com/hg mercurial-repo
real URL is http://www.selenic.com/hg/
requesting all changes
adding changesets
adding manifests
adding file changes
added 6908 changesets with 13429 changes to 976 files
updating working directory
861 files updated, 0 files merged, 0 files removed, 0 files unresolved

这会建立一个 mercurial-repo的新目录, 复制整个项目的历史记录, and check out the tipmost changeset (see also Clone).

查看哪一个revision被checked out:

$ cd mercurial-repo
$ hg parents
changeset:   6907:6dcbe191a9b5
tag:         tip
user:        Matt Mackall <mpm@selenic.com>
date:        Mon Aug 18 16:50:36 2008 -0500
summary:     Fix up tests

3. 建立新的Mercurial项目

你希望从创建一个仓库开始:

$ cd project/
$ hg init           # 创建 .hg

Mercurial 将会在您repository的根目录查找名为.hgignore的文件,该文件用于设定需要忽略文件的格式或正则表达式。以下是一个.hgignore文件的例子:

syntax: glob
*.orig
*.rej
*~
*.o
tests/*.err

syntax: regexp
.*\#.*\#$

以下代码测试.hgignore文件的效果:

$ hg status         # 显示所有没有被忽略的差异文件

这将会列出所有没有被忽略的文件。这些文件名前带有'?'号(表示mercurial没有跟踪它们)。编辑你的.hgignore 文件直到status中只列出了你想要的文件为止。You'll want to track your .hgignore file too! But you'll probably not want to track files generated by your build process. Once you're satisfied, schedule your files to be added, then commit:

$ hg add            # add those 'unknown' files
$ hg commit         # commit all changes, edit changelog entry
$ hg parents        # see the currently checked out revision

4. Clone, Commit, Merge

$ hg clone project project-work    # clone repository
$ cd project-work
$ <make changes>
$ hg commit
$ cd ../project
$ <make other changes>
$ hg commit
$ hg pull ../project-work   # pull changesets from project-work
$ hg merge                  # merge the new tip from project-work into our working directory
$ hg parents                # see the revisions that have been merged into the working directory
$ hg commit                 # commit the result of the merge

参见: Clone, Commit, Pull, Merge, Parent

5. 导出补丁

(make changes)
$ hg commit
$ hg export tip    # export the most recent commit

参见: Export

6. 网络支持

# clone from the primary Mercurial repo
foo$ hg clone http://selenic.com/hg/
foo$ cd hg

# update an existing repo
foo$ hg pull http://selenic.com/hg/

# export your current repo via HTTP with browsable interface
foo$ hg serve -n "My repo" -p 80

# push changes to a remote repo with SSH
foo$ hg push ssh://user@example.com/hg/

参见: Serve, Push, Pull


translations: German Portuguese Japanese Thai


CategoryChinese CategoryChinese CategoryChinese

ChineseQuickStart (last edited 2012-02-22 03:25:04 by 125)