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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With