Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Move to previous and next commit

I need a way to quickly move to the previous and next commit in a git branch.

For the previous I found that I can do:

git reset --hard HEAD~1

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

And ideal solution would use 2 alias git prev and git next.

Thanks

like image 643
Pablo Fernandez Avatar asked Apr 05 '11 16:04

Pablo Fernandez


1 Answers

There is a handy alias setup by git called ORIG_HEAD which keeps track of the last head used. So when you do a git reset --hard HEAD~1 the data about the head you just reset away from is stored in ORIG_HEAD.

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

like image 137
jkeating Avatar answered Oct 01 '22 09:10

jkeating