Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial: graft vs. record vs. qrecord vs. shelve vs. transplant vs. dirstate vs. queue

I am new to Mercurial and still somehow in the evaluation process, so these four concepts are kind of confusing for me. Some are mentioned to be an equivalent to Git's Staging/Index concept, or some even a better one than Git's Staging.

How do the four commands hg graft, hg record, hg qrecord and hg shelve (and hg transplant, but this is explained in Graft vs. Transplant already) compare to each other, and how the concepts of queues and the dirstate? In which use cases is one choosen over the other?

I know there are help pages for each one, but it still is difficult to figure out what each one does as VCS in general is a new topic for me.

like image 938
Iodnas Avatar asked Nov 29 '12 17:11

Iodnas


1 Answers

The design of Mercurial simply does not include the concept of a staging area. That is, there is no intermediate state between local modification and commit.

Here is an overview of each of the concepts you mentioned:

hg graft is the equivalent of git cherry-pick. It copies a commit from one branch to another. A typical use case for this feature is to copy a bug fix from one release branch to another. This command replaces the older (and now obsolete) hg transplant extension.

hg record and hg qrecord are similar to git add --patch. They allow you to interactively select hunks for commit. So if you modified several different areas of one file, you could select which areas (i.e. hunks) you actually want to commit and which you want to leave as local modifications.

qrecord is only available if you have mq enabled. It commits to an mq patch rather than a standard commit.

hg shelve is similar to git stash. It allows you to temporarily set aside local modifications to your files (or hunks of a file). These modifications can then be unshelved when you are ready for them.

dirstate is an internal class of of the Mercurial source code. It is not exposed to the user.

Mercurial Queues (also know as mq) are probably the closest you will get to a staging area in Mercurial. Here is a description from the Mercurial wiki:

Changes are maintained as patches which are committed into Mercurial. Commits can be removed or reordered, and the underlying patch can be refreshed based on changes made in the working directory. The patch directory can also be placed under revision control, so you can have a separate history of changes made to your patches.

mq is often used to polish/rework commits that you are testing locally, but have not pushed to a public location. Some people also use it to maintain a set of modifications to 3rd party code.

like image 123
Tim Henigan Avatar answered Oct 01 '22 13:10

Tim Henigan