Pablo Fernandez
Pablo Fernandez

Reputation: 105220

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

Upvotes: 8

Views: 6744

Answers (1)

jkeating
jkeating

Reputation: 1154

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

Upvotes: 4

Related Questions