Junio C Hamano <junkio@xxxxxxx> writes: > The standard way to check if commit A is included in (i.e. is an > ancestor of) commit B, without traversing the ancestry chain of > B all the way down to the root commit, is to run: > > git merge-base --all A B > > and see if A appears in its output (if so, then A is an ancestor > of B, otherwise it is not). This is a pair-wise check, and for > your purpose the check would become N*M operation (Yuck). > > The same check can be done in parallel with: > > git show-branch --independent A B C D... > > whose output would include A if the commit is not included in > any of the other commits B C D... This parallel traversal has a > limit --- you can only check 25 branches at a time. Well, I was silly. If you want to see if A is an ancestor of any of B C D..., the standard and most efficient way to do so is with rev-list. git rev-list A --not B C D... will show _nothing_ only when A is an ancestor of one (or more) of B C D..., so you invoke it and upon getting the first line of output you declare A cannot be removed without reading the remainder of the output. show-branch --independent is an overkill for your purpose as it does not treat A any more special from others (iow, it checks if B is contained in A C D..., C is contained in A B D... all in parallel), and you are not interested in finding out how remote refs are related with each other. - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html