In git, there is no real efficient way to get the children of a commit. Any commit will have a pointer to its parents, not to its descendants that do not exist when the commit is created.
There is a possibility that there are children commit for which the branch reference has been deleted (so, these are commits that could be pruned at next garbage collection), or children commit that are part of the history of one or more existing branches.
However git 1.6 introduced --children
in the rev-list
command. It probably has to scan each commit that is “reachable from” (in git terminology, means “an ancestor of”) every single local and remote branch ref.
git rev-list
will list all descendants with no depth limitation, in the format commit_id parent_1_commit_id [parent_2_commit_id [...]]
. Therefore you will have to grep for the head commit ID in the second column to get the commit ids of its descendants.
Thus:
git rev-list --children HEAD | grep " $(git show --format=format:%H HEAD)"
You can make out a bash function to alias this to git children
:
[alias]
children = "!f(){ git rev-list --children \"$1\" | grep \" $(git show --format=format:\"%H\" \"$1\")\" | cut -f 1 -d ' '; }; f"
Then git children HEAD
will give you the commit ids of all descendants of HEAD.