How do I find the next commit in git? (child/child

2019-01-02 20:01发布

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?

14条回答
残风、尘缘若梦
2楼-- · 2019-01-02 20:30

There is no unique "next commit". Because history in Git is a DAG, and not a line, many commits can have a common parent (branches), and commits can have more than one parent (merges).

If you have a particular branch in mind, you can look at its log and see what commit lists the present one as its parent.

查看更多
闭嘴吧你
3楼-- · 2019-01-02 20:30

If the child commits are all on some branch, you can use gitk --all commit^.., where "commit" is something identifying the commit. For example, if the commit's abbreviated SHA-1 is c6661c5, then type gitk --all c6661c5^..

You will probably need to enter the full SHA-1 into gitk's "SHA1 ID:" cell. You will need the full SHA-1, which for this example can be obtained via git rev-parse c6661c5

Alternatively, git rev-list --all --children | grep '^c6661c5883bb53d400ce160a5897610ecedbdc9d' will produce a line containing all the children of this commit, presumably whether or not there is a branch involved.

查看更多
登录 后发表回答