Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to checkout a commit's child?

How do I reference a commit ahead of HEAD?

For example, a commit that is 1 commit behind HEAD is HEAD~1.

How do I move the opposite direction, with respect to HEAD?

Basically, I did a git checkout HEAD~1 3 times. Now I want to move forward 1 commit, effectively undoing my last git checkout HEAD~1. How can I do this?

I understand that a branch of commits is like a singly linked list, with each commit only pointing to its parent. So if it unreasonable to traverse to a commit's child, I would like to know how to process forward between them.

like image 411
modulitos Avatar asked Mar 06 '16 06:03

modulitos


1 Answers

A commit can have unlimited children. If you want to see all the histories that trace back to a commit you can

git log --all --ancestry-path ^$commit

or just

git branch --contains $commit
git tag --contains $commit

to show their names.

with whatever display options you want. If you want to automate finding commits whose parent is a particular commit you could start with

child-commits() { 
        git rev-list --all --ancestry-path --parents ^$1^{} \
        | awk /$(git rev-parse $1^{})'/ {print $1}'
}

But if you just want to see where you've been, use

git reflog

to show what's affected your HEAD, and why.

like image 122
jthill Avatar answered Oct 14 '22 10:10

jthill