Last Updated: December 26, 2018
·
6.703K
· nono

Git prev & next

When you are doing a talk with a demo in several steps, it can be practical to have a git repository with a commit for each step. During the demo, when you want to go to the next step, all you have to do is moving to the next commit. But, except if you know the sha1 of this commit, it can be tricky to do that without interrupting your talk. I have two git aliases to suggest for this task (in ~/.gitconfig):

[alias]
    prev = checkout HEAD^1
    next = "!sh -c 'git log --reverse --pretty=%H master | awk \"/$(git rev-parse HEAD)/{getline;print}\" | xargs git checkout'"

With them, you can move to the next step with a simple git next and come back to the previous step with git prev. Just be warned, it'll only works on the master branch.

1 Response
Add your response

Thanks a lot,

I saw this in a PHP demo and wondered how it's done.

over 1 year ago ·