Is it possible to get the list of revisions that direct descendants of A that are direct ancestors of B? I I try git log A..B I will get the list of revisions that are ancestors of B that are not in the history of A, which is not exactly what I want. I need only revisions that directly connect A and B.
git - get direct descendants of A that connect to B
138 Views Asked by eftshift0 At
1
Yes: add
--ancestry-pathto your revision specification. (This works for any command that uses commit-graph-walking, includinggit logandgit rev-list.) But I will note that I'm not sure what you mean by the adjective "direct" here.Note that
A..BmeansB ^A, i.e., use the setancestors(B) - ancestors(A)(where subtraction here is set-subtraction). Adding--ancestry-pathmeans that after doing the set subtraction (or more accurately, while constructing the subtracted set), Git also subtracts away any commit that is not a descendant of the negated revisionA.Internally, Git does this by marking negated commit hash IDs (like
AinA..BorB ^A) with a flag called BOTTOM. Such commits are collected into a "bottom list" and Git makes sure that each commit C that might be in theA..Brange has a bottom-commit as one of its ancestors. This matters if you usegit rev-list --ancestry-path X ^Y ^Zfor instance: commits can be descendants ofYorZ.\Here's an example graph fragment showing which commits are selected (
●) or not-selected (○) even though they are "in the range" ofA..B:Note that commit
Ais not selected, and commitBis selected, here.