Version Control with Mercurial

Key Points

Automated Version Control
  • Version control is like an unlimited ‘undo’.

  • Version control also allows many people to work in parallel.

Configuring Mercurial
  • Use hg config to configure a user name, email address, editor, and other preferences once per machine.

Creating a Repository
  • hg init initializes a repository.

Tracking Changes to Files
  • hg status shows the status of a repository.

  • hg add puts files in the staging area.

  • hg commit saves the staged content as a new commit in the local repository.

  • Always write a log message when committing changes.

Making Changes
  • hg diff displays differences between commits.

  • hg log shows the history of a repository.

Exploring History
  • Use hg diff to compare different versions of files.

Recovering Old Versions
  • Use hg revert to recover old versions of files.

Ignoring Things
  • Create a .hgignore file to specify things that Mercurial should ignore.

Remote Repositories
  • Use hg push to push changes to remote repositories.

  • Use hg pull to pull changes from remote repositories.

Working with Clone Repositories
  • Use hg clone to make a local copy of a remote repository.

Collaboration
  • Set access to ‘public’ or ‘private’ to control who can see what.

Merging Changes from Different Clones
  • Use hg merge to combine independent changes to the same set of files.

Merge Conflicts
  • Conflicts occur when two or more people change the same file(s) at the same time.

  • The version control system does not allow people to overwrite each other’s changes blindly, but highlights conflicts so that they can be resolved.

Open Science
  • Open scientific work is more useful and more highly cited than closed.

Licensing
  • People who incorporate GPL’d software into their own software must make their software also open under the GPL license; most other open licenses do not require this.

  • The Creative Commons family of licenses allow people to mix and match requirements and restrictions on attribution, creation of derivative works, further sharing, and commercialization.

  • People who are not lawyers should not try to write licenses from scratch.

Hosting
  • Projects can be hosted on university servers, on personal domains, or on public forges.

  • Rules regarding intellectual property and storage of sensitive information apply no matter where code and data are hosted.

A Better Kind of Backup

Collaborating

Conflicts

Open Science

Glossary

changeset
A group of changes to one or more files that are committed to a version control repository in a single operation.
clone
To make a local copy of a version control repository. See also: fork.
commit
To record the current state of a set of files (a changeset) in a version control repository.
conflict
A change made by one user of a version control system that is incompatible with changes made by other users. Helping users resolve conflicts is one of version control’s major tasks.
fork
To clone a version control repository on a server.
HTTP
The Hypertext Transfer Protocol used for sharing web pages and other data on the World Wide Web.
infective license
A license such as the GPL that compels people who incorporate material into their own work to place similar sharing requirements on it.
Internet Service Provider (ISP)
A company or other organization that provides access to the Internet. Many ISPs provide hosting services for websites.
merge
To reconcile two sets of changes to a repository.
protocol
A set of rules that define how one computer communicates with another. Common protocols on the Internet include HTTP and SSH.
remote
A version control repository other than the current one that the current one is somehow connected to or mirroring.
repository
A storage area where a version control system stores old revisions of files and information about who changed what, when.
resolve
To eliminate the conflicts between two or more incompatible changes to a file or set of files being managed by a version control system.
revision
A recorded state of a version control repository.
SSH
The Secure Shell protocol used for secure communication between computers.
timestamp
A record of when a particular event occurred.
version control
A tool for managing changes to a set of files. Each set of changes creates a new revision of the files; the version control system allows users to recover old revisions reliably, and helps manage conflicting changes made by different users.