Git Checkout Directly to a Specific Commit

Electric Lazer Eyez

If you’d like to experiment with a previous commit, you can get to it with laser focused precision.

Rather than doing a git revert or the more destructive (and dangerous) git reset, you can do a read-only branch directly to a specific place in your git history.

Finding the commit you need.

There’s 2 ways you can view your previous commits, by typing git log in your terminal, or by viewing your commits in your GitHub repository.

It’s usually a really long string. For example: 19ad132a79fe0b75ba0b99432e0f1e8e06f9a000.

Check that sh*t out.

Copy the commit you’d like. In GitHub, you can click the little “copy” icon to the left of the number, or just copy it directly from your git log. (Side note: if you’re viewing a long git log in terminal, to exit the view just type the letter q.)

Let’s assume you’re in the master branch. When you type git checkout 19ad132a79fe0b75ba0b99432e0f1e8e06f9a000, it will instantly create a new read-only branch exactly at the commit you’ve specified. You can now experiment in this new branch as much as you’d like – install new gems, etc – and generally it will not do anything destructive to your master branch.

Keep that sh*t.

If you want to keep that read-only branch into a new branch, just type git checkout -b new_branch_name where “new_branch_name” is a new name of your choosing.

Leave that sh*t behind.

After experimenting, if you don’t want to keep your read-only experiment you can go back to your master branch by typing git checkout master. The read-only version of the branch you created now magically vanishes.

If you get an error that does not allow you to go back to the master, you may need to delete the read-only branch you created. Warning: make sure you’re deleting the correct branch as this completely destroys it. To delete the read only branch, git branch -d the_branch_name. If that doesn’t work, try git branch -D the_branch_name.


Sublime Keyboard Shortcuts

Here are some of my favorite Sublime keyboard shortcuts for the Mac:

Keypress Description
Ctrl + Cmd + Up Arrow Move Line Up
Ctrl + Cmd + Down Arrow Move Line Down
Cmd + k + b Show/hide side bar
Cmd + ? Remark/Unremark
Cmd + D Selects the next repeated word
Opt + Arrow Moves the cursor by a full word
Opt + Shift + Arrow Moves and selects by a full word
Cmd + Enter Creates a new line under
Cmd + Shift + Enter Creates a new line above

For a full list: Windows | Mac


If you liked it, you should’ve put a string on it.

What’s the difference between a puts, print, and p statement in Ruby?

I was running a tutorial today and came across a print statement. As it was the first time I’d seen one, I looked it up.

Basically, puts adds a new line after executing while print does not.

As an aside, I also learned that puts actually stands for “put string”. Thank goodness. I was always bothered by how grammatically incorrect “putsing” something sounded. I guess I’m grateful that it isn’t typed out as put_s similar to to_s. Although it would have made more sense and been more consistent, that underscore, which is awkward to type, would likely add an exponential amount of time to our writing code given how often we type it.

And as for the p statement, it outputs it as an object, so you can see it as it appears in code rather than it being formatted differently. For example if you did a puts of an array, it would output each value on a separate line, whereas a p statement would write it all out on one line similar to how you’ve written it out in your code.

If you’d like to dig more into these common commands, you can get details of each in the Kernel method of Ruby: