From the perspective of a Git user Initialize a repository and create a default branch: hg init Status of a repository: hg status Meaning of the symbols displayed: ? file untracked. A file added for tracking/commit. M file modified. ! file missing. R file marked for removal. To add files to …
From the perspective of a Git user
Initialize a repository and create a default branch:
hg init
Status of a repository:
hg status
Meaning of the symbols displayed:
? file untracked.
A file added for tracking/commit.
M file modified.
! file missing.
R file marked for removal.
To add files to track:
hg add
Without argument, this command adds all files. Unlike Git, it is not necessary to add modified files again before next commit.
Commit changes:
hg commit
hg log
view commit/changeset logs. Use ``--limit NUM`` to limit displayed logs by NUM (number).
hg revert file
to revert a modified file to the one from last commit. Modified file is saved as ``file.orig``.
hg revert --all
to revert all files as in the last commit.
hg diff
to view changes since last commit. ``hg diff file`` to view changes
for the give file.
hg cat -r 0 file
to view the specific version (0, in this case) of a file. Similarly,
hg diff -r 0:1 file
to view difference between versions (0 and 1, in this case).
hg diff -r default:stable
to view differences between two branches (``default`` and ``stable``).
hg update NUM
to update working directory to revision NUM. ``hg update`` with no options updates to the most recent commit.
hg parent
to see what commit/changeset the working directory is in.
hg tip
to view the most recent commit.
hg push
to push changes to a central repository.
hg pull repo_url
pull changes from remote repository. Note: this does not update working directory. To
do that use ``hg update``. Alternatively, ``hg pull -u`` does the same function.
hg merge
to perform a merge
Tips
Short log
.........
An useful alias to display a short log (source <http://hgtip.com/tips/beginner/2009-10-07-shortlog-for-fun-and-profit/>
_). ::
log --template '{rev}:{node|short} {desc|firstline}\n'
Add to ~/.hgrc
::
[alias]
slog = log --template '{rev}:{node|short} {desc|firstline}\n'
Then do hg slog
.
Revision/commit numbers ....................... It is sufficient to use the short number displayed to refer to a specific revision. For example ::
$ hg log
changeset: 1:15894d57f0f0
tag: tip
user: Vimalkumar Velayudhan <v@....com>
date: Tue Jan 20 12:21:35 2015 +0000
summary: modified test file
changeset: 0:42219304850b
user: Vimalkumar Velayudhan <v@....com>
date: Tue Jan 20 12:16:01 2015 +0000
summary: added test file
To display the log for changeset 0:42219304850b
::
hg log -r0
Refer remote repository by names during push
For example, add to ~/.hgrc
(change repository URL accordingly) ::
[paths]
bitbucket = ssh://hg@bitbucket.org/vkvn/testing
To push to this repo, ::
hg push bitbucket
Remove untracked files
::
hg st -un0 | xargs -0 rm
source: http://stackoverflow.com/a/1212893
Todo
http://mercurial.selenic.com/wiki/PagerExtension
Issues/Questions
Modified files are added for the next commit automatically. There should be a way to commit files selectively. For example, I have a file with changes that I dont’t want to commit yet.
Reference
- http://hginit.com
Comments