I have tried the
hg log --rev "branch([changeset])"
but what I got is a collection of all the changesets in this branch.
What I do want to get is the name of the target branch (e.g. default) instead of the whole collection.
Is there a way to achieve this goal?
That's... not what revsets are for. You want to do something rather different:
hg log --rev [changeset] --template "{branch}\n"
See hg help templates.
Related
I'm looking for a method like hg backout, but in reverse. Specifically, instead of undoing the diffs associated with a given changset, I want to actually apply them on top of an arbitrary revision. Is this possible?
hg transplant (bundled extension) or hg graft (core, since 2.0) do this.
I stopped using hg fetch to pull and merge in another head for a Mercurial repository because I like to make the commit message say what is merging with what. Furthermore, I am moving from "merge repo1 -> repo2" to a more specific "merge head1guid -> head2guid" format.
How can I automate this so I don't have to list the heads with hg heads then copy and paste the guids for the two changesets into my commit message?
As others have pointed out in comments the one or two parents of a changeset are already stored in a changeset and shown in hg log and other command line views -- You're probably better off not re-storing them.
If you really wanted to you could do something like:
hg commit -m "merging $(hg log -r . --template '{parents}')"
but I always try to put something actually useful in the message like "Merging Jim's work on foo into Alice's work on bar"; there's no new information in re-storing the nodeids of the parents.
Note that command only works when you're committing a merge -- it'll be empty otherise.
I'd like to get an hg status list for a range of revisions, and also filter the list for a given branch name.
e.g. The issue with this command is that it includes changes from multiple branches, and I'm only interested in a particular branch:
hg status --rev 150:175
Is there a way to add an additional filter by branch for this list with hg or a mainstream hg tool?
You can do this using revsets:
hg status --rev "150:175 and branch(<BRANCH_NAME>)"
I believe that you can use revsets (hg help revsets) to do this. There are a large number of options for selecting revisions, but I think that what you want would be something along these lines:
hg status --rev "150:175 and branch(mybranch)"
Revsets can be tricky at times, but they are very powerful, and so well worth reading about them in hg help.
If I have two heads in my repo - C and D which have the common parent of B - and I do an hg merge then a hg commit, what exactly is in that merge changeset? I am trying to understand what I see what I do hg diff -c xyz where xyz is the id of the merged changeset.
Will the changeset show the diffs of all files modified in C and D vs. the state of those files as they existed in the common parent repository B?
A merge commit has two parents, so when running a diff it is important to understand which parent you are diffing against.
hg diff -c <changeset> shows the diff of the changeset relative to the first parent.
From hg help diff:
diff may generate unexpected results
for merges, as it will default to
comparing against the working
directory's first parent changeset if
no revisions are specified.
To diff against a specific parent, it is best to provide the explicit revision of both the merge changeset and corrent parent (e.g. hg diff -r <parent> -r <merge changeset>
Mercurial implements a directed acyclic graph so in your merge changeset depends on where you're coming from. When you type "hg merge" it assumes "tip" (much in the same way hg pull assumes the root repository from which you cloned your head) If you type "hg heads" you can see which one is the tip. When you do this merge, assuming C as the tip, you are merging in the changes from D.
I want to remove a changeset from history but hg export does not work for merge changesets (see https://www.mercurial-scm.org/wiki/Export). Is there a way to use hg pull for a range of revisions? For example, say I want to remove revision 999 I want to be able to say:
hg init NewRepo
hg pull ../OldRepo -r 0:1000
hg pull ../OldRepo -r 1000:tip
Any ideas?
Pull can't pull a range of revisions because every mercurial revision that exists in a repository must have all of its ancestor changesets in that revision too. So if you do:
hg pull ../oldRepo -r 1000
you get all of revision 1000's ancestor revisions too.
In general, mercurial is about building an immutable history -- if you regret a changeset you don't remove it you create a new one that undoes the work of the changeset you no longer like. If you can't abide having full history in your repo you need to use something like the strip or convert extension. Both work as advertised, but provide plenty of opportunities to shoot yourself in the foot. If you can stand it, just undo the onerous changeset in a subsequent changeset and move on.