Mercurial Cheatsheet
#
Mercurial is a distributed version control system used for tracking changes in source code during software development. It was developed by Matt Mackall and released in 2005. Mercurial efficiently handles projects of any size and offers an easy and intuitive interface. It is designed to support multiple workflows and includes branching and merging capabilities.
Repository Management
#
Command/Option | Example | Description |
---|
hg init | hg init | Initialize a new Mercurial repository |
hg clone | hg clone https://example.com/repo | Clone an existing repository |
Staging and Committing
#
Command/Option | Example | Description |
---|
hg add | hg add file.txt | Add a file to the repository |
hg commit (ci) | hg commit -m "Commit message" | Record changes to the repository |
hg status (st) | hg status | Show the status of files in the working directory |
hg diff | hg diff | Show differences between revisions |
Branching and Merging
#
Command/Option | Example | Description |
---|
hg branch | hg branch new-branch | Create a new branch |
hg update (up) | hg update new-branch | Switch to a different branch |
hg merge | hg merge new-branch | Merge changes from another branch |
hg rebase | hg rebase -s source -d dest | Reapply changes from one branch to another |
Remote Repositories
#
Command/Option | Example | Description |
---|
hg pull | hg pull | Pull changes from a remote repository |
hg push | hg push | Push changes to a remote repository |
hg paths | hg paths | Show aliases for remote repositories |
Undoing Changes
#
Command/Option | Example | Description |
---|
hg revert | hg revert file.txt | Revert a file to its previous state |
hg remove (rm) | hg remove file.txt | Remove a file from the repository |
hg rollback | hg rollback | Roll back the last transaction in the repository |
Viewing History and Logs
#
Command/Option | Example | Description |
---|
hg log | hg log | Show commit logs |
hg annotate | hg annotate file.txt | Show changeset information by line for each file |
hg summary | hg summary | Show a summary of the working directory state |
Command/Option | Example | Description |
---|
hg tag | hg tag v1.0 | Add a tag for the current changeset |
hg tags | hg tags | List tags |
hg bookmark | hg bookmark new-feature | Create a bookmark at the current changeset |
hg bookmarks | hg bookmarks | List bookmarks |
Repository Maintenance
#
Command/Option | Example | Description |
---|
hg verify | hg verify | Verify the integrity of the repository |
hg clean | hg clean | Remove unknown files from the working directory |
hg bundle | hg bundle repo.hg | Create a bundle containing changesets |
Miscellaneous
#
Command/Option | Example | Description |
---|
hg help | hg help | Show help for commands |
hg config | hg config | Show combined global and per-repository configurations |
hg serve | hg serve | Start a web server for the repository |
hg archive | hg archive -r rev destination | Create an unversioned archive of a repository |
This cheatsheet covers the most commonly used Mercurial commands and options, helping you to manage repositories, commits, branches, merges, and more effectively.