I have a few 开发者_如何转开发branches and a commit with ID X, I want Mercurial to return me a list of branches where that commit exists.
Mercurial already stores information about branch in every commit, but only about a branch in which that commit was introduced. If you merge that commit into some other branch, commit will still store only original branch name.
I think you could get what you want with this formula
hg log -r 'descendants(X) and head()'
head()
includes all named branch heads, so even if the tip of a branch has been merged into another named branch, it will still be listed with this formula.
If you only want to show branch names, you will probably want to use the --template '{branches}\n'
directive for the hg log
command. If you have more than one head per named branch, you may end up using uniq
or similar.
EDIT: To describe what this will do
A----B----C----D----E Branch: default (E is a merge of F into D)
\ \ \ /
\ \ F Branch B1 (closed)
\ G-----H Branch B2
\ \
\ I Branch B2
J Branch B3
If you execute hg log -r 'descendants(C) and head()'
, you should get E, F, H and I.
- E: You get E, because 'default' is a branch head, even though it has a special name.
- F comes up because even though you merged into E, it's still a
head()
, so it shows up on this list - G is not a head, although it does contain C
- H is a head and clearly a descendant of C
- I branched from G, is also a head, and clearly contains C
- J is a head, but does not have C as an ancestor
精彩评论