Linux中国
Mercurial 版本控制入门

Mercurial 是一个用 Python 编写的分布式版本控制系统。因为它是用高级语言编写的,所以你可以用 Python 函数编写一个 Mercurial 扩展。
在官方文档中说明了几种安装 Mercurial 的方法。我最喜欢的一种方法不在里面:使用 pip
。这是开发本地扩展的最合适方式!
目前,Mercurial 仅支持 Python 2.7,因此你需要创建一个 Python 2.7 虚拟环境:
python2 -m virtualenv mercurial-env
./mercurial-env/bin/pip install mercurial
为了让命令简短一些,以及满足人们对化学幽默的渴望,该命令称之为 hg
。
$ source mercurial-env/bin/activate
(mercurial-env)$ mkdir test-dir
(mercurial-env)$ cd test-dir
(mercurial-env)$ hg init
(mercurial-env)$ hg status
(mercurial-env)$
由于还没有任何文件,因此状态为空。添加几个文件:
(mercurial-env)$ echo 1 > one
(mercurial-env)$ echo 2 > two
(mercurial-env)$ hg status
? one
? two
(mercurial-env)$ hg addremove
adding one
adding two
(mercurial-env)$ hg commit -m 'Adding stuff'
(mercurial-env)$ hg log
changeset: 0:1f1befb5d1e9
tag: tip
user: Moshe Zadka <[moshez@zadka.club][4]>
date: Fri Mar 29 12:42:43 2019 -0700
summary: Adding stuff
addremove
命令很有用:它将任何未被忽略的新文件添加到托管文件列表中,并移除任何已删除的文件。
如我所说,Mercurial 扩展用 Python 写成,它们只是常规的 Python 模块。
这是一个简短的 Mercurial 扩展示例:
from mercurial import registrar
from mercurial.i18n import _
cmdtable = {}
command = registrar.command(cmdtable)
@command('say-hello',
[('w', 'whom', '', _('Whom to greet'))])
def say_hello(ui, repo, `opts):
ui.write("hello ", opts['whom'], "n")
简单的测试方法是将它手动加入虚拟环境中的文件中:
`$ vi ../mercurial-env/lib/python2.7/site-packages/hello_ext.py`
然后你需要启用扩展。你可以仅在当前仓库中启用它:
$ cat >> .hg/hgrc
[extensions]
hello_ext =
现在,问候有了:
(mercurial-env)$ hg say-hello --whom world
hello world
大多数扩展会做更多有用的东西,甚至可能与 Mercurial 有关。 repo
对象是 mercurial.hg.repository
的对象。
有关 Mercurial API 的更多信息,请参阅官方文档。并访问官方仓库获取更多示例和灵感。
via: https://opensource.com/article/19/4/getting-started-mercurial
作者:Moshe Zadka 选题:lujun9972 译者:geekpi 校对:wxy
本文转载来自 Linux 中国: https://github.com/Linux-CN/archive
对这篇文章感觉如何?
太棒了
0
不错
0
爱死了
0
不太好
0
感觉很糟
0
5 Comments
Leave a reply
More in:Linux中国
如何通过 VLC 使用字幕
使用 VLC 媒体播放器播放和管理字幕的新手指南。
Unix 桌面:在 Linux 问世之前
仅仅开源还不足以实现开放,还需开放标准和建立共识。
Valve 对于 Ubuntu 的 Snap 版本的 Steam 并不满意:原因何在
你可能会发现,Snap 版本的 Steam 并不如你期待的那样好,你怎么看?
Wine 9.0 发布,实验性地加入了 Wayland 驱动
Wine 的这个新版本正在为未来做好准备!
350fairfax Nordvpn coupons Inspiresensation
It’s appropriate time to make some plans for the longer
term and it is time to be happy. I have learn this post and if I could I want
to counsel you few fascinating things or tips. Maybe you could write next articles regarding this article.
I wish to read even more things approximately it!
Good day! This is kind of off topic but I need some guidance from an established
blog. Is it very hard to set up your own blog? I’m not
very techincal but I can figure things out pretty quick.
I’m thinking about making my own but I’m not sure where to begin. Do you
have any points or suggestions? Appreciate it
my page; nordvpn coupons inspiresensation; cia.sh,
Admiring the commitment you put into your blog and in depth information you present.
It’s good to come across a blog every once in a while that isn’t the same old rehashed material.
Great read! I’ve bookmarked your site and I’m
including your RSS feeds to my Google account.
Here is my web site: nordvpn Coupons inspiresensation
Wow that was unusual. I just wrote an very long comment but after I clicked submit my comment didn’t show up.
Grrrr… well I’m not writing all that over again.
Anyways, just wanted to say excellent blog!
Here is my website; nordvpn coupons inspiresensation
Hello, this weekend is fastidious for me, because this occasion i am reading
this fantastic educational paragraph here at my residence.
Here is my web blog: nordvpn coupons inspiresensation (easyurl.cc)