Mercurial for Beginners: The Definitive Practical Guide

Inspired by Git for beginners: The definitive practical guide.

This is a compilation of information on using Mercurial for beginners for practical use.

Beginner - a programmer who has touched source control without understanding it very well.

Practical - covering situations that the majority of users often encounter - creating a repository, branching, merging, pulling/pushing from/to a remote repository, etc.

Notes :

  • Explain how to get something done rather than how something is implemented.
  • Deal with one question per answer.
  • Answer clearly and as concisely as possible.
  • Edit/extend an existing answer rather than create a new answer on the same topic.
  • Please provide a link to the the Mercurial wiki or the HG Book for people who want to learn more.
  • Questions:

    Installation/Setup

  • How to install Mercurial?
  • How to set up Mercurial?
  • How do you create a new project/repository?
  • How do you configure it to ignore files?
  • Working with the code

  • 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?
  • Tagging, branching, releases, baselines

  • How do you 'mark' 'tag' or 'release' a particular set of revisions for a particular set of files so you can always pull that one later?
  • How do you pull a particular 'release'?
  • How do you branch?
  • How do you merge branches?
  • How do you merge parts of one branch into another branch?
  • Other

  • Good GUI/IDE plugin for Mercurial? Advantages/disadvantages?
  • Any other common tasks a beginner should know?
  • How do I interface with Subversion?
  • Other Mercurial references

  • Mercurial: The Definitive Guide
  • Mercurial Wiki
  • Meet Mercurial | Peepcode Screencast
  • Mastering Mercurial | TekPub Screencast
  • Hg Init - ground-up Mercurial tutorial

  • How do you configure it to ignore files?

    Ignore is configured in a normal text file called .hgignore in the root of your repository. Add it just like a normal file with:

    hg add .hgignore
    

    There are two syntax options available for file matching, glob and regexp. glob is unix-like filename expansion and regexp is regular expressions. You activate each by adding syntax: glob or syntax: regexp on a line by itself. All lines following that will use that syntax, until the next syntax marker. You can have as many syntax markers as you want. The default syntax is regexp, so if you only use regexp you don't need any syntax marker.

    You can add comments with #

    Example:

    # python temporary files
    syntax: glob
    *.pyc
    
    #editor autosaves
    *~
    
    # temporary data
    syntax: regexp
    temp
    

    Ignore only applies to unmanaged files (ie files that are not already checked in). To ignore files that are under version control, you can use the switches -I and -X.


    How do you see what's uncommitted, or the status of your current codebase?

    To see a list of files that have been changed:

    $ hg status
    

    This will print each file that has been changed along with its status, which can include:

  • 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.
  • To see the changes that have actually been made to the files:

    $ hg diff
    

    你如何创建一个新的项目/存储库?

    $ hg init my-repository
    
    链接地址: http://www.djcxy.com/p/6402.html

    上一篇: Mercurial Eclipse插件

    下一篇: 初学者的Mercurial:最终实用指南