hg commands

http://stevelosh.com/blog/2010/08/a-git-users-guide-to-mercurial-queues/

http://hgbook.red-bean.com/read/mercurial-in-daily-use.html

1. Getting started

 
x
1
#-- create .hgrc in home dir
2
$cd ~
3
$vim .hgrc
4
    [ui]
5
    username = Xianwei Zhang <xianweiz@nvidia.com>
6
    editor = vim
7
8
    [extensions]
9
    mq =
10
#-- create repo. setting up a new Mercurial project
11
$hg init .
12
#ignore files using a set of glob patterns and regular expressions
13
$touch .hgignore
14
#-- track files (place the files under version control), include names matching the given patterns. done, "?" --> "A"
15
$hg add -I "*.cpp"
16
$hg add -I "*.hpp"
17
$hg add -I "*.c"
18
$hg add -I "*.h"
19
$find . -name "*.cpp" | xargs hg add
20
# tells which files Mercurial doesn't know about (uses a "?" to display such files)
21
# by default, `hg status` only tells about interesting files -- modified, removed or renamed, etc
22
$hg status
23
# stop tracking a file
24
$hg remove <file>
25
$hg status  # a removed file is represented in the output of `hg status` with a "R"
26
# Mercurial considers a file that u have deleted, but not used `hg remove` to delete, to be missing ("!")
27
$rm <file>
28
$hg status
29
# want the missing file to stay gone
30
$hg remove --after <file>
31
$hg status
32
# on the other hand, recover the missing file
33
$hg revert <file>
34
$hg status
35
#-- check files
36
$hg status -q
37
#-- untrack
38
$hg forget *
39
#-- commit, preserve files in the repo
40
#-- after commit, added files will no longer be listed in the output of `hg status`
41
$hg commit -m "msg"
42
#-- list commits
43
$hg log

2. Patch

 
xxxxxxxxxx
30
1
#-- prepares a rep to work with MQ. This cmd creates an empty directory called ".hg/patches", where MQ will keep its metadata
2
$hg qinit
3
#-- to begin work on a new patch
4
$hg qq -c xianwei_smart
5
$hg qq
6
    patches
7
    xianwei_smart (active)
8
## --
9
# create a single patch with `hg qnew <NAME>`
10
# make changes in ur working directory
11
# use `hg qrefresh` to put them into the patch
12
# `hg qfinish` once u'r done with the patch and ready for it to become a commit
13
## --
14
#create a "patch holder" which will contain the changes that we make
15
#-- create a "patch holder" which will contain the changes that we make
16
#-- also newly present in the ".hg/patches" directory are two other files, "series" and "status"; the "series" file lists all the patches that MQ knows about for this repo, and "status" file tracks all of the patches that MQ has applied in this repo
17
$hg qnew mod1.patch
18
    .hg/patches-xianwei_smart/mod1.patch
19
#-- edit files
20
$vim vts_datapath.cpp
21
#-- see changes
22
$hg dif
23
#-- update the patch with the new changes; this cmd folds the changes u have made in the working directory into your patch, and updates its corresponding changeset to contain those changes
24
$hg qrefresh
25
#-- see record patch changes
26
$vim .hg/patches-xianwei_smart/mod1.patch
27
#-- "qrefresh" is kind of checkpoint. afterwards, try an experiment, and it it doesn't work, "hg revert" your modifications back to the last time u refreshed
28
$hg revert
29
#-- once u'r done working on a patch and want to turn it into a permanent changeset
30
$hg qfinish

3. More on patch

An applied patch has a corresponding changeset in the repo, and the effects of the patch and changeset are visible in the working directory. You can undo the application of a patch using the qpop command. MQ stills knows about, or manages, a popped patch, but the patch no longer has a corresponding changeset in the repo, and the working directory does not contain the changes made by the patch.

 
xxxxxxxxxx
46
1
#-- pop patches off the stack, removes applied patches
2
# "qpop -a": pop all applied patches
3
$hg qpop
4
    popping mod1.patch
5
    patch queue now empty
6
#-- push patches onto the stack; the patch's changes once again become present in the working directory
7
#-- "qpush -a": push all unapplied patches
8
$hg qpush
9
    applying mod1.patch
10
    nw at: mod1.patch
11
#-- list available patches
12
$hg qseries
13
#-- list applied patches
14
$hg qapplied
15
    
16
#-- working on several patches at once
17
#-- "qrefresh" always refresh the topmost applied patch
18
#-- so, we can suspand work on one patch (by refreshing it), pop or push to make a different patch the top, and work on that patch for a while
19
20
#-- do backup
21
$mkdir ~/Backups
22
$mv .hg ~/Backups/
23
$ls -s ~/Backups/.hg/ .
24
25
$hg qq -c mem_packet_tracking
26
$hg help qimport
27
$hg qimport -e
28
/home/scratch.arg_nvresearch/patches_for_Xianwei/implement_restartQ.patch
29
$hg qimport -e                 
30
/home/scratch.arg_nvresearch/patches_for_Xianwei/track_packets_thru_mem_pipe.patch
31
# lists every patch that MQ knows about in this repository
32
$hg qser(ies)
33
    implement_restartQ.patch
34
    track_packets_thru_mem_pipe.patch
35
$vim .hg/patches-mem_packet_tracking/series
36
# lists every patch that MQ has applied in this repo
37
$hg qapplied
38
$hg status -a ./smartlib/sm_knob_db.cpp
39
40
#push all unapplied patches
41
$hg qpush -a
42
#pop all applied patches
43
$$hg qpop -a
44
45
#remove patch
46
$hg qq --purge mem_packet_tracking

4. Misc

 
xxxxxxxxxx
1
$p4 changes -m1
2
  Change 36868433 on 2016/07/19 by pgupta@internalClient_client.VVsKQC 'changes made due to change in t'
3
$vim /home/azulfiqar/.vimrc
4
$make clean all
5
$make vts -j8 > myBuild.txt
6
# DirDiff