How do I find the next commit in Git? (child/children of ref)
Solution 1:
To list all the commits, starting from the current one, and then its child, and so on - basically standard git log, but going the other way in time, use something like
git log --reverse --ancestry-path 894e8b4e93d8f3^..master
where 894e8b4e93d8f3 is the first commit you want to show.
Solution 2:
The creator of Hudson (now Jenkins), Kohsuke Kawaguchi published (November 2013): kohsuke / git-children-of:
Given a commit, find immediate children of that commit.
#!/bin/bash -e
# given a commit, find immediate children of that commit.
for arg in "$@"; do
for commit in $(git rev-parse $arg^0); do
for child in $(git log --format='%H %P' --all | grep -F " $commit" | cut -f1 -d' '); do
git describe $child
done
done
done
As illustrated by this thread, in a VCS based on history represented by a DAG (Directed Acyclic Graph), there is not "one parent" or "one child".
C1 -> C2 -> C3
/ \
A -> B E -> F
\ /
D1 -> D2 ----/
The ordering of commits is done by "topo-order" or "date-order" (see the GitPro book).
But since Git 1.6.0, you can list the children of a commit.
git rev-list --children
git log --children
Note: for parent commits, you have the same issue, with the suffix ^
to a revision parameter meaning the first parent of that commit object. ^<n>
means the <n>
th parent (i.e. rev^
is equivalent to rev^1
).
If you are on branch foo
and issue "git merge bar
" then foo
will be the first parent.
I.e.: The first parent is the branch you were on when you merged, and the second is the commit on the branch that you merged in.