ref^
refers to the commit before ref
, what about getting the commit after ref
?
For example, if I git checkout 12345
how do I check out the next commit?
Thanks.
PS Yes, git's a DAG node pointer struct tree whatever. How do I find the commit after this one?
Two practical answers:
One Child
Based on @Michael's answer, I hacked up the
child
alias in my.gitconfig
.It works as expected in the default case, and is also versatile.
It defaults to giving the child of HEAD (unless another commit-ish argument is given) by following the ancestry one step toward the tip of the current branch (unless another commit-ish is given as second argument).
Use
%h
instead of%H
if you want the short hash form.Multiple children
With a detached HEAD (there is no branch) or to get all children regardless of branches:
Change the
$1
to$*
to print all the children.You can also change
--all
to a commit-ish to display only the children which are ancestors of that commit—in other words, to display only the children “in the direction of” the given commit. This may help you narrow the output down from many children to just one.I have this alias in
~/.gitconfig
In the case where you don't have a particular "destination" commit in mind, but instead want to see child commits that might be on any branch, you can use this command:
If you want to see all children and grand-children, you have to use
rev-list --children
recursively, like so:(The version that gives only grand-children would use a more complex
sed
and/orcut
.)Finally, you can feed that into a
log --graph
command to see the tree structure, like so:The creator for Hudson (now Jenkins) Kohsuke Kawaguchi just published (November 2013):
kohsuke / git-children-of:
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".
The ordering of commits is done by "topo-order" or "date-order" (see GitPro book)
But since Git1.6.0, you can list the children of a commit.
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 torev^1
).If you are on branch
foo
and issue "git merge bar
" thenfoo
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.
I've tried many different solutions and none worked for me. Had to come up with my own.
find next commit
find previous commit
I managed to find the next child the following way: