Git: go to previous and next commit

I need a way to quickly jump to the previous and next commit in git branches.

In the previous, I found that I can do:

git reset --hard HEAD~1

And it's probably an alias that in git prev or something, but I can't figure out how to move "up" to the next commit.

And the ideal solution would be to use 2 aliases git prev and git next .

thanks

+7
source share
1 answer

There is a convenient alias setting with git called ORIG_HEAD, which tracks the last used header. Therefore, when you do git reset --hard HEAD ~ 1, the data about the head that you only reset away is stored in ORIG_HEAD.

so the alias git prev git reset --hard HEAD ~ 1 (or HEAD ^ 1) and the alias git next to git reset --hard ORIG_HEAD

+5
source

All Articles