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)