In this situation:
v HEAD
o--o--o--x--o--o (foo)
/
o--o--o--o--o--o--o (master)
If I want to move one step backward I type:
$ git checkout HEAD~1
v HEAD
o--o--o--x--o--o (foo)
/
o--o--o--o--o--o--o (master)
If I want to move a step forward I came with this ridiculous command:
$ git log --pretty=oneline --all | \
grep -B1 `git rev-parse HEAD` | \
head -n1 | egrep -o '[a-f0-9]{20,}' | xargs git checkout
v HEAD
o--o--o--x--o--o (foo)
/
o--o--o--o--o--o--o (master)
Can I do better such as git checkout HEAD+1
?
My current implementation in my ~/.gitconfig
is:
[alias]
# Move forward/Backward
fw = "!git log --pretty=oneline --all | grep -B1 `git rev-parse HEAD` | head -n1 | egrep -o '[a-f0-9]{20,}' | xargs git checkout"
bw = "!git checkout HEAD~1"
Git commits have pointers back to their parents, which is why you can go backwards. They do not have pointers to their children, so you cannot "go forwards," as you are trying to do. The best you can do is look at the git log
and determine the hash of the commit you want to checkout.
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