If come from an svn background (like I do) this would seem a natural question.

I’ve introduced a bug, I want to checkout/revert to an older version so I can find it. How do I do that with git?

The problem (or answer) with git is that you don’t have to ‘checkout’ old versions of your code. They are already there.

Git keeps track of everything you have ever done with your code base locally.

This is very powerful because now that everything is local, you can seamlessly switch between older commits simply by creating local branches based off your SHA1 commit hash.

By switching between branches at your command line, and hitting cntrl-r to quickly reload your app, you can quickly tracking down where exactly you introduced your bug.

$ git checkout -b aNewBranch1 SHA1 (test)
$ git checkout -b aNewBranch2 SHA2 (test)
$ git checkout -b aNewBranch3 SHA3 (got it!)

And you can clean up your branches after like so:

$ git branch -D aBranchToDelete

This is a powerful workflow you can’t do with svn. It’s something I initially didn’t appreciate with git and it’s changed how I track down bugs.

Thanks to VonC for his great explanation here on stackoverflow.

Advertisements