Another Japan in the World

Jun Aruga's blog, who lived in Japan, Singapore, live in Czech Republic. Mainly about IT and travel.

Mercurial training

I started to use Mercurial that is another source code management (SCM) tool such as Git.

Nowadays there are many SCM tools, such as CVS, SVN, VSS, Git, Mercurial.

CVS, SVN, and VSS is central repository management tool. Those are already yesterday's tool. Ruby language itself is using SVN as a primary repository.

Git and Marcurial are distributed repository management tool. Python language itself and a python package are using Marcurial. That is a reason that I started to use it.

As Git and Marcurial are distributed repository management tool for each other. The commands are similar [1]

So, let's try.

Try for commands!

Let me use below repository as my training. [2][3] BitBucket is supporting not only Git, but also Marcurial. It may be their unique strength for Github. The official document is useful too [4]

Initial setting

Create config file like ~/.gitconfig. below editor line is to prevent an error "abort: edit failed: vi exited with status 1" after hg commit on Mac. Mac vi exits with exit status non-zero, and it causes the error for hg.

$ vi ~/.hgrc
[ui]
username = Your Name <yourname@example.com>
editor = /usr/bin/vim

Clone

$ hg clone ssh://hg@bitbucket.org/blais/snakefood

$ cd snakefood

Help

$ hg help

Mercurial Distributed SCM

list of commands:

 add           add the specified files on the next commit
 addremove     add all new files, delete all missing files
 annotate      show changeset information by line for each file
 archive       create an unversioned archive of a repository revision
 backout       reverse effect of earlier changeset
 bisect        subdivision search of changesets
 bookmarks     create a new bookmark or list existing bookmarks
 branch        set or show the current branch name
 branches      list repository named branches
 bundle        create a changegroup file
 cat           output the current or given revision of files
 clone         make a copy of an existing repository
 commit        commit the specified files or all outstanding changes
 config        show combined config settings from all hgrc files
 copy          mark files as copied for the next commit
 diff          diff repository (or selected files)
 export        dump the header and diffs for one or more changesets
 files         list tracked files
 forget        forget the specified files on the next commit
 graft         copy changes from other branches onto the current branch
 grep          search for a pattern in specified files and revisions
 heads         show branch heads
 help          show help for a given topic or a help overview
 identify      identify the working directory or specified revision
 import        import an ordered set of patches
 incoming      show new changesets found in source
 init          create a new repository in the given directory
 log           show revision history of entire repository or files
 manifest      output the current or given revision of the project manifest
 merge         merge another revision into working directory
 outgoing      show changesets not found in the destination
 paths         show aliases for remote repositories
 phase         set or show the current phase name
 pull          pull changes from the specified source
 push          push changes to the specified destination
 recover       roll back an interrupted transaction
 remove        remove the specified files on the next commit
 rename        rename files; equivalent of copy + remove
 resolve       redo merges or set/view the merge status of files
 revert        restore files to their checkout state
 root          print the root (top) of the current working directory
 serve         start stand-alone webserver
 status        show changed files in the working directory
 summary       summarize working directory state
 tag           add one or more tags for the current or given revision
 tags          list repository tags
 unbundle      apply one or more changegroup files
 update        update working directory (or switch revisions)
 verify        verify the integrity of the repository
 version       output version and copyright information

additional help topics:

 config        Configuration Files
 dates         Date Formats
 diffs         Diff Formats
 environment   Environment Variables
 extensions    Using Additional Features
 filesets      Specifying File Sets
 glossary      Glossary
 hgignore      Syntax for Mercurial Ignore Files
 hgweb         Configuring hgweb
 merge-tools   Merge Tools
 multirevs     Specifying Multiple Revisions
 patterns      File Name Patterns
 phases        Working with Phases
 revisions     Specifying Single Revisions
 revsets       Specifying Revision Sets
 scripting     Using Mercurial from scripts and automation
 subrepos      Subrepositories
 templating    Template Usage
 urls          URL Paths

(use "hg help -v" to show built-in aliases and global options)

or

$ hg help command

or

$ hg command --help

Branch

Show branches. How do you see remote branches?

$ hg branches
default                      291:6d55510bd30b
python3-via-six              289:d115ece5c850
python3                      281:02b62c749462
configure-dpi                290:f271f333586e (inactive)

Show current branch.

$ hg branch
default

Pull

It looks same with git pull.

$ hg pull

Check summary of current status

Check summary

$ hg sum
parent: 291:6d55510bd30b tip
 Merged in paavoap/snakefood/configure-dpi (pull request #3)
branch: test-branch
commit: 1 modified (new branch)
update: (current)

Check logs

Such as git log

$ hg log | less
changeset:   291:6d55510bd30b
tag:         tip
parent:      288:fa88cf9c3827
parent:      290:f271f333586e
user:        Martin Blais <blais@furius.ca>
date:        Sat Jun 04 18:52:27 2016 -0400
summary:     Merged in paavoap/snakefood/configure-dpi (pull request #3)

changeset:   290:f271f333586e
branch:      configure-dpi
parent:      288:fa88cf9c3827
user:        Paavo Parkkinen <paavoap@sg.ibm.com>
date:        Mon May 30 16:10:32 2016 +0800
summary:     Add 'dpi' command line option to sfood-graph.

...

Commit

$ vi README
$ hg status
M README

README is tracked (registered). So, do not need to use hg add FILE.

$ hg diff
diff -r 6d55510bd30b README
--- a/README  Sat Jun 04 18:52:27 2016 -0400
+++ b/README  Tue Dec 20 12:54:36 2016 +0100
@@ -137,3 +137,8 @@
 ======

 Martin Blais <blais@furius.ca>
+
+
+Test Subject
+======
+Teet message.
$ hg commit

Check own commit.

$ hg log | less

Add remote repository

No such kind of command git remote add. Add new repo from file.

Added junaruga line after doing folk from bitbucket.org.

$ vi .hg/hgrc
...
[paths]
default = ssh://hg@bitbucket.org/blais/snakefood
junaruga = ssh://hg@bitbucket.org/junaruga/snakefood
...

Check added repository URLs.

$ hg paths
default = ssh://hg@bitbucket.org/blais/snakefood
junaruga = ssh://hg@bitbucket.org/junaruga/snakefood

Push

I referred this page. [5]

$ hg push junaruga --new-branch -r test-branch

After pushing, check pushed branch on your bitbuket.org repo page.

References

Remove all ads