Last Updated: February 25, 2016
·
483
· timurstrekalov

Git - go back to previous revision

I've found being able to go to the previous working directory in shell extremely useful - this can be achieved by doing

cd -

Which is effectively the same as

cd $OLDPWD

Today, I figured: it would be great if I could do the same with Git when it comes to changing between revisions. I decided to try it (you can see the current branch in parentheses) :

timur@timur: test (master) $ git branch
  feature-x
* master
timur@timur: test (master) $ git checkout feature-x 
Switched to branch 'feature-x'
timur@timur: test (feature-x) $ git checkout -
Switched to branch 'master'
timur@timur: test (master) $ git checkout -
Switched to branch 'feature-x'
timur@timur: test (feature-x) $

And it worked, just as expected, allowing you to switch between two branches very quickly.

UPDATE The "-" shortcut seems to work for merge just as well, so there might be more to this.