Can hg log show only the ancestors of a given revision?
One thing I really miss moving from svn to mercurial is that mercurial's hg log com开发者_如何学编程mand insists on showing all history rather than only the history of my current working revision.
For example, I'm working on a repo with a lot of check-ins to another head within my branch, and the first 20 log entries have nothing to do with my line of development.
There are a bunch of options to hg log, but...
--rev shows the revision asked for but not its ancestors --branch doesn't work because the active head is in the same branch as mine --prune removes all ancestors of the other head, even if they're also my ancestors --user doesn't work because I'm not the only user in this line of developmentI guess I could hg strip, but that seems like overkill...
Thoughts?
RyanIf you've got Mercurial 1.6 or later, you can use revsets to do this:
hg log --rev "ancestors(.)"
hg log --rev "reverse(ancestors(.))" # Output in the same order as vanilla hg log
I know revision sets is all the rage these days (hg log -r "::."
), but the little-known --follow
flag lets you do what you want using any version of Mercurial. The hg log
help says (my emphasis in bold):
[...] Use
-f/--follow
with a filename to follow history across renames and copies.--follow
without a filename will only show ancestors or descendants of the starting revision. [...]If no revision range is specified, the default is tip:0 unless
--follow
is set, in which case the working directory parent is used as the starting revision. [...]
So, in other words, adding -f
will do the trick for you. You can add -f
to your defaults:
[defaults]
log = -f
or better yet, you can create an alias for this:
[alias]
logf = log -f
That avoids changing a core command like hg log
, which will probably confuse you or your colleagues sooner or later.
As Niall C said, you can do this from the command line using revsets:
hg log --rev "ancestors(.)"
Also, if you have TortoiseHg, you can filter the revision graph in the Repository Explorer using the radio buttons marked "All", "Tagged", "Ancestry", "Parents", "Heads", "Merges" and so on just above your history. In this case, you would select the revision whose ancestry you are interested in and then choose the "Ancestry" option.
精彩评论