'Retrieve the list of child commits of a specific commit in Git

I was wondering whether there is an efficient way to retrieve the children of a given commit. Although a method was discussed in Referencing the child of a commit in Git, it is very inefficient.

I thought this would be a straightforward thing to be done in Git, but apparently, it is not.

git


Solution 1:[1]

I use the following alias (based on @Lily Ballard's answer:

# Get all children of current or specified commit-ish
children = "!bash -c 'c=${1:-HEAD}; set -- $(git rev-list --all --not \"$c\"^@ --children | grep $(git rev-parse \"$c\") ); shift; echo $*' -"
  • With no argument - gives all children of HEAD
  • With a commit-ish - gives all children of that object

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Søren Løvborg