灵感来自Git初学者:权威的实用指南。

这是一个关于初学者实际使用Mercurial的信息汇编。

初学者——一个接触过源代码控制却没有很好地理解它的程序员。

实用——涵盖大多数用户经常遇到的情况——创建存储库、分支、合并、从远程存储库拉/推到远程存储库等等。

注: 解释如何完成某件事,而不是解释某件事是怎样的 实现的。 回答一个问题。 回答清楚,尽可能简洁。 上编辑/扩展现有答案,而不是创建新答案 同样的话题。 请为想了解更多的人提供Mercurial wiki或HG Book的链接。

问题:

安装/设置

如何安装Mercurial? 如何设置Mercurial? 如何创建一个新的项目/存储库? 如何将其配置为忽略文件?

使用代码

How do you get the latest code? How do you check out code? How do you commit changes? How do you see what's uncommitted, or the status of your current codebase? How do you remove files from the repository? How do you destroy unwanted commits? How do you compare two revisions of a file, or your current file and a previous revision? How do you see the history of revisions to a file or repository? How do you handle binary files (visio docs, for instance, or compiler environments)? How do you merge files changed at the "same time"? How do you revert a Changeset? How do you go back to a previous version of the code? How do you extract a patch from a specific changeset? How do you record that you renamed or deleted a file without using the Mercurial command?

标记、分支、发布、基线

你如何“标记”、“标记”或“发布”一组特定文件的特定修订,以便以后总是可以提取它? 你如何进行特定的“释放”? 你如何分支? 如何合并分支? 如何将一个分支的部分合并到另一个分支中?

其他

好的GUI/IDE插件Mercurial?优点/缺点? 还有其他初学者应该知道的常见任务吗? 如何与Subversion交互?

其他Mercurial参考资料

Mercurial:权威指南 Mercurial维基 满足Mercurial |偷窥码屏幕播放 掌握Mercurial | TekPub屏幕播放 Hg初始化-接地水银教程


当前回答

如何将一个分支的部分合并到另一个分支中?

在。hg/hgrc中启用“移植”扩展名

[extensions]
transplant=

加载目标分支,然后移植目标修订版本。 例如:樱桃挑选修订版81从分支'foo'到当前分支

$ hg transplant -b foo 81

其他回答

如何获得最新的代码?

Mercurial会记住存储库是从哪里克隆的(在.hg/hgrc中),所以你可以简单地运行:

hg pull

从原始存储库中提取最新的代码。(这不会更新工作目录)

hg update

更新工作目录。

hg pull -u

同时执行拉取和更新。

如何从特定的变更集中提取补丁?

$ hg export -o patchfile changeset

然后你可以导入到另一个分支:

$ hg import patchfile

您如何查看未提交的内容或当前代码库的状态?

要查看已更改的文件列表:

$ hg status

这将打印每个已更改的文件及其状态,包括:

M - Modified. The file has been changed and the changes have not been committed. A - Added. The file was not tracked before, but if you commit Mercurial will begin tracking it. R - Removed. The file was tracked before, but if you commit Mercurial will cease tracking it in this and future commits. ? - Unknown. The file is not currently tracked by Mercurial. Committing will have no effect on it unless you use hg add to add it. ! - Missing. The file was tracked but Mercurial cannot find it in the working copy.

要查看实际对文件所做的更改:

$ hg diff

如何提交更改?

从当前本地* mercurial存储库调用此命令

hg commit [OPTION]... [FILE]...

别名:CI

本地mercurial存储库的当前目录中有.hg

选项为:

 -A --addremove     mark new/missing files as added/removed before committing
    --close-branch  mark a branch as closed, hiding it from the branch list
 -I --include       include names matching the given patterns
 -X --exclude       exclude names matching the given patterns
 -m --message       use <text> as commit message
 -l --logfile       read commit message from <file>
 -d --date          record datecode as commit date
 -u --user          record user as committer

一个示例命令是:

hg commit -m "added readme" README

注:

如果省略了一个文件列表,所有由"hg status"报告的更改都将被提交。 如果提交合并的结果,不要提供任何文件名或-I/-X过滤器。 如果未指定提交消息,则启动已配置的编辑器以提示您输入消息。

如何签出代码?

hg clone [OPTION]... SOURCE [DEST]

选项为:

 -U --noupdate      the clone will only contain a repository (no working copy)
 -r --rev           a changeset you would like to have after cloning
    --pull          use pull protocol to copy metadata
    --uncompressed  use uncompressed transfer (fast over LAN)
 -e --ssh           specify ssh command to use
    --remotecmd     specify hg command to run on the remote side

其中source是存储库中原始文件的源,可以是远程URL或文件系统目录。例如:

http://bitbucket.org/scrum8/django-wmd-editor/ /home/username/repository/django-wmd-editor / ssh: / / myusername@scrum8.com/ ~ /仓库/ django-wmd-editor /

destination是源代码在本地文件系统中的位置。