# Go forward in Git commit hierarchy, towards particular commit
# Usage:
# gofwd v1.2.7
# Does nothing when the parameter is not specified.
gofwd() {
git checkout $(git rev-list --topo-order HEAD.."$*" | tail -1)
}
# Go back in Git commit hierarchy
# Usage:
# goback
alias goback='git checkout HEAD~'
$ git reflog show
4444444 (HEAD -> main) HEAD@{0}: reset: moving to 4444444
1111111 HEAD@{1}: commit: F
2222222 HEAD@{2}: commit: E
3333333 HEAD@{3}: commit: D
4444444 (HEAD -> main) HEAD@{4}: commit: C
5555555 HEAD@{5}: commit: B
6666666 HEAD@{6}: commit: A
git reflog # Here we get all the commits we need
grep -A 1 $(git rev-parse --short HEAD) # Here we grep for the short commit hash
awk '{print $1}' # Here we get just the hash
tail -1 # We will get at least 2 results, pick the last line, the first would be 0
xargs -I {} git checkout {} # Here we go "forward by 1"