I just broke my codebase. I want to rollback to my last commit, but I want to save off the broken version first, so I can analyze it later. What’s the best course in this situation?
(I haven’t actually tried anything, just looking for some hand-holding- It’s been a long day and I don’t feel like screwing this up..)
There are a few things you can do:
Most likely the best thing for you to do is to create a separate branch to commit this broken code on, and commit to that branch.
When you want to go back to that code, do a
git checkout my-broken-branchto change over to that branch.A quick thing you can do is
git stash, which will save your work and you can reapply it later:When you want to get those changes back, you can do a
git stash applywhich will apply the last changes you stashed away (but keep the information in the stash list).As Andrew mentioned in the comments, you can also do
git stash pop, which will apply the least stashed changes, and remove it from the stash list.There is more you can do with stashing, since you can do multiple stashes and selectively apply them back.
Here’s a more detailed explanation when you want to get more in-depth on stashing: http://gitready.com/beginner/2009/01/10/stashing-your-changes.html