About mercurial (HG)

Source: Internet
Author: User
Tags mercurial

Transferred from

Decided to use mercurial (HG)
Http://www.keakon.cn/bbs/thread-1865-1-1.html

========================================================== ======================================

Recently I wanted to use version control software to save Chinese files, but I thought SVN was too troublesome. So I came up with a popular distributed version control tool.
Git and mercurial (mercurial, often abbreviated as Hg) are naturally the most popular tools. The well-known Linux uses Git for source code management, while Python and Firefox use Hg (you can find a bunch of projects using Hg here ).
After comparison, I finally chose the latter. Because git's main advantage lies in its branches, and localization does not require too many branches, git's support for Windows seems to be inferior to mercurial, and SSH is more troublesome than HTTP, which is hard to be used by members of the localization group; another special reason is that Hg is mainly implemented in Python (a small part is implemented in C ).
Of course, Hg also has a serious drawback: it does not support the branch for a single folder. If you want to build a branch for script translation and rebuild, you must copy the entire repository. for translation, image files are not what they need.

In addition, Google also published analysis of git and mercurial, explaining why Google Code decided to support Hg rather than git.
Git advantages:

  • Client storage control. You can delete any version without having to consider the subsequent version of the branch.
  • Unlimited number of parent nodes. Hg can only be divided into two branches at a time. Merging n branches requires many operations. Git has no restrictions.
  • Supports rebase. It can move the current version to the latest branch. For example, assume that a local database is developing a new feature of 1.0, and the baseline has been upgraded to 1.1. Generally, it needs to be merged to 1.1, and rebase can avoid this operation.

Advantages of Hg:

  • Learning curve. Due to many factors, git has a steep learning curve than HG.
  • Windows is supported.
  • Maintenance. Git needs regular maintenance.
  • History cannot be violated. Git is very powerful and can do almost anything, so it will also lose historical information.

It seems that git is technically better than HG, but because the implementation of file operations depends on the operating system, porting to bigtable will be troublesome; in addition, Hg has a good HTTP-based stateless pushing and pulling, which is easy to integrate with Google's architecture (almost all Google services are based on HTTP ).
Google also provides test data specifically, indicating that git is one order of magnitude slower than HG When HTTP is used. (Two numbers are mentioned, which are 22 times slower and 12 times slower .)

Before continuing to introduce Hg, let's talk about distributed configuration management (DSCM, Distributed Software Configuration Management ).
SVN, which has been used for a while before, is also a very popular tool in centralized SCM. My impression is that the speed is slow (because every file is downloaded separately, and the speed cannot be reached at all). Each folder contains a. SVN folder that affects my mood.
It took several hours of Hg today, and it was obviously different.
First, it is fast. Both upload and download are packaged and compressed. I uploaded a 7 m project that took only a few minutes and took up 4 MB of space. I have to say that the compression rate is very high.
The second is that the repository is distributed. You can create multiple images locally and then change the images separately. Submitting only the images locally does not affect the master repository; each Warehouse can also be merged to reach the consistency of multiple versions, and then uploaded to the master warehouse.
This is very convenient for Chinese translation, because the translators can build their own images and inform the school Translation after the translation is completed. The school translators can obtain the versions of each translation and merge them. After the school translation is completed, the readers will notice the improvement; you can obtain the translated version and then push it to the main repository. Because the master Warehouse does not need to be changed multiple times, it avoids the confusion of management by establishing multiple branches in the master warehouse.

By the way, I found several websites that can be used to host code for free:

  • GitHub: This website is famous for its MB free space built with ror. It supports git, but does not support Hg (although there are plug-ins, it is too troublesome to teach others ), there is no private library.
  • Bitbucket: This is created using Django. You can create a private library, free space of MB, and support for Hg.
  • Projectlocker: only (unlimited) Private libraries, free space of MB, support for SVN and git, but only 5 users. Closed-source project recommendation, but obviously not suitable for a large Tomo Chinese group.
  • Unfuddle: Free Space of MB. It supports SVN and git and can only have one database and two users.

In the end, I chose the smallest Bitbucket, because it is almost enough.
(Note: Google Code now supports Hg, but it can only host source code and cannot be used for other purposes, so I can only give up. However, if you are developing open-source software, Google Code is the most generous. You can also send a mail application to expand the quota, but occasionally get gFW .)

Then we started to install the software. I am used to SVN turtles, so I still chose tortoisehg ).
Currently, this version supports Windows XP, Vista, and Windows 7, so you do not have to worry about compatibility.
The installation is very simple. After the installation is complete, you need to restart (in fact, you can also use it without restarting ).
If you like the command line, you can also enter Hg in cmd to try.

However, after installation, the interface is in English. I don't know if my operating system is the cause of the English system.
I flipped through the document (C:/program files/tortoisehg/docs/tortoisehg.pdf) and found that it actually supports Chinese, however, you need to create an environment variable "language" (in system attributes) with the value "zh_cn ".
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/1.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">
Then you have to go to this folder: C:/program files/tortoisehg/cmenu_i18n to import the thg-cmenu-zh_CN.reg file.
After the modification, the software interface and command line (Hg and hgtk) are now in Chinese, but the right-click menu is still in English. Restart or log out to become Chinese.

Before using mercurial, we recommend that you take a look at the mercurial tutorial to learn about several terms.
Init refers to initialization, that is, creating an empty repository.
Clone refers to the creation of a repository. The source can be an HTTP or SSH link or a local repository.
Commit refers to the submission, that is, accepting all changes and using the current version as the latest version (also called tip ). Note that this submission is different from the centralized SCM. It only submits the local repository, and the local repository records all changes in detail (called Change set or change set ). Therefore, it is okay to submit multiple times because it does not affect others' warehouses. If you are afraid of affecting yourself, you can clone a duplicate and then rewrite and submit it.
A revert is a restoration, that is, all changes are revoked and restored to the unchanged state. You cannot find it in the right-click menu.
Pull means to pull the changes that are available in other warehouses but not in the current warehouse to the current warehouse. However, this only adds a change set, and the file will not be changed. (The change set has a unique hash ID, so it is easy to differentiate .)
Update means update. When other Change sets are obtained and the changes need to be consistent with those of other warehouses, You can execute the update.
Push means to upload the change set of the current warehouse to another warehouse. Other repositories must support this operation and may need to be verified. If it is pushed from the local warehouse A to the local warehouse B, it is equivalent to using B pull. In addition, push does not update the repository version, because it is shared, and you can directly select the desired version.
Merge means merge. When a file is modified multiple times and stored in multiple warehouses, a unified version must be obtained and merged. For translation, a text may be distributed to multiple people at the same time, so you only need to accept the changes made by each person during the merge.
If you want to learn more, read mercurial: the definitive guide.

After the introduction of these terms, you can look at the usage methods written by others:
Git vs mercurial Hg? Remote Collaborative Development and distributed SCM solution selection!
Codebeamer + mercurial Practical Operation Manual
Of course, that PDF document is also useful.

However, for the sake of the comrades in the localization group, I 'd like to explain how to complete the operation.

First, go to my Bitbucket homepage and find the familyproject project.
The following are some tips:

Reference:

Clone this repository (size: 4.3 MB): https/ssh
$ Hg clone https: // keakon@bitbucket.org/keakon/familyproject/

Create a folder named familyproject anywhere on your hard disk.
Go to the folder, right-click the blank space, and select "clone" from the tortoisehg menu ".

Fill in the address you just saw in the Source Path: https: // keakon@bitbucket.org/keakon/familyproject/, and then click the "clone" button, wait until the download is complete.

After the download is complete, you have a complete project file, and you can modify it.

Next, perform a clone operation and copy it to another local repository. The method is very simple. It is the same as the previous clone, but fill in the generated folder in the source path, and fill in the new folder in the target path:

This operation should be completed in 1 or 2 seconds, because it is a local copy.

Then open a file in familyproject in a text editor, such as snr02.isf.
In the following 1st sentence, we will find that: ● 0001 ● too many errors were lost.
Change it to: Read failed.
Right-click the familyproject folder and select "Hg submit ".

The modified files and specific differences are listed. Enter the description and click Submit.
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/6.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">

Open the file with the same name in familyproject-new, and find the 2nd sentence: ● 0002 ● deleted too many characters.
Change it to: Read failed.
Then perform the same commit operation.

Now you have two different branches in two warehouses, so you can see how to merge them.
Right-click the familyproject folder and select "Hg repository Browser ".

Enter the address of the new warehouse in the address bar and click "pull change set:
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/8.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">
At this time, you will find that the latest tip version has changed to the version in familyproject-new and has an additional branch.
However, it remains unchanged after opening the file. In this case, right-click the change set at the top and select "Update" (you can also select "pull and update" in the previous step to automatically complete the operation) to switch the version.
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/9.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">
Note that the version has been listed, and there are several prompts, such as the change set number, the change set hash ID, description, and whether it is the default or tip version.
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/10.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">
Click the "Update" button after confirmation. Then you will find that your file has changed to the version in familyproject-new, but your changes are lost (don't be nervous, file is not lost ).
The reason is very simple. The update is only to switch the version of the change set and will not be merged. If you want to switch back to your version, right-click the change set below and select "Update.

However, my goal is to merge rather than update, so we will continue to describe the merge below.
The operation is simple. Right-click 2nd branches and select "merge.
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/11.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">
Click "merge.
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/12.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">
Since the changes are different, there is no conflict, and the merger is successful. Click Submit.
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/13.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">
In this case, the changes are listed. "-" indicates deletion, and "+" indicates addition. We can see that the two changes are correct, so we don't need to do anything else, just click the "Submit" button.
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/14.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">
Let's take a look at the change set. The branches have been merged, and your files have been updated.
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/15.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">

However, the files in familyproject-New are still old versions.
If you don't need it, simply delete the folder. If you want to continue using the folder, open its "Hg repository Browser" and select "pull and update ", click "pull change set:
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/16.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">
After the operation, the two warehouses are exactly the same, and you can continue other operations.

If you have finished the modification and need to pass it to others, you need to push it to others or ask others to come to pull. This operation is actually similar to the operation in the Local warehouse.
The simplest method is to publish to a local web server.
Right-click the folder and choose tortoisehg-web server ":

A window appears (as mentioned above, it is easy to see that it is written in Python), but don't worry, you have to click "Configure" to set it:

Set "SSL encryption push" to "false" because you do not have an SSL certificate. Enter the Allowed User Name in "allow push". In order to save the trouble, enter "*" to allow everyone to push. The following encoding must also be the same as the file encoding, so as to avoid gibberish during online file viewing.

Return after confirmation. Enter a number smaller than 65535 in the port. The default value is 8000. Then click "start.

After it is started, you can access it through a browser. The address is http: // your IP: Port Number /.

Next, try pushing.
Open the familyproject-new folder, change the file, and submit it.
This time I don't need a repository browser, because it is too large, and I switched to a small "synchronization" Operation:

Enter the address you just accessed in the browser, and click "push" to complete the push.
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/23.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">
Then you can go to the familyproject folder to view the change set. If necessary, you can perform the update and merge operations as mentioned above.

However, this IP address may be inaccessible from the outside, or may be caused by the gateway or firewall settings, so that your web server cannot be accessed by others.
A temporary solution is mail. But before that, you have to change the email settings.
Right-click the folder and choose tortoisehg-global settings ":

Fill in your email information in "email:

Here is the configuration instructions for Gmail. Just fill in the other settings.
Note that the password is the logon password of the mailbox. If you fill it out, it will be saved in plain text, so if your computer is still in use, do not fill it out, but you need to manually enter the password when sending the mail.

Return to the synchronization window after configuration. Click "mail" and enter the mail content. Check the attachment and click send.
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/26.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">
However, if the network is poor, it is likely to fail. After successful, the recipient will receive an email containing an attachment of the. Patch type.
However, tortoisehg does not support importing the patch file and can only be executed through the command line.
The receiver can run cmd, switch to the warehouse to be imported, and then execute the following command:

Reference:

Hg import patch file name

Of course, the command line is terrible for some people, so another method is to create your own repository in Bitbucket.
You can register an account or use openid.
Log on to the familyproject and click the fork link.
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/27.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">
Fork refers to creating a copy based on my repository. Similar to clone, it is only performed remotely.
On the New Page, enter the project name, click "Advanced Settings", perform more settings, and click "create fork" to create a project.

Like local clone, the remote fork completes in a few seconds and is automatically redirected to this repository. (The result shows that this warehouse is actually half-sized, so it seems that the space usage is very strange .)
{
Zoom (this, this. SRC)
} "Src =" https://dl.dropbox.com/u/1065182/Picture/TortoiseHg/29.png "border =" 0 "alt =" decided to use mercurial (HG)-keakon's blog-"width =" 600 ">

Next, you can operate the repository in the same way as the self-built web server.
When you need to notify others after the change, go to the familyproject project again and click the "pull request" button.
Enter the email content on the new page, attach your repository address, and select the person to be notified. Then, click "Send request" to send the email.
The recipient of the email can go to your warehouse to perform the pull Operation to obtain the update.

The merge and other operations are also mentioned before, so we will not repeat them.
If the space is insufficient, creating an account is the most convenient method.
Of course, you can also go to the "admin" label and click the "delete repository" button in the lower right corner to delete unnecessary warehouses.
In addition, there is a "repository management" link. after entering the link, you can perform the Strip operation to delete unnecessary versions.
However, it seems that no space is added after deletion, so it's depressing... So I sent a mail to the customer service, but it hasn't been done for a whole day. Our communication frequency is about 2 hours...

It seems that there is nothing else to say, so this tutorial is over.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.