Will Farrington - Big Nerd Ranch Tue, 19 Oct 2021 17:46:46 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 Git Treeishes Considered Awesome https://bignerdranch.com/blog/git-treeishes-considered-awesome/ https://bignerdranch.com/blog/git-treeishes-considered-awesome/#respond Wed, 18 Jan 2012 12:00:00 +0000 https://nerdranchighq.wpengine.com/blog/git-treeishes-considered-awesome/

A Street Called Awesome

The post Git Treeishes Considered Awesome appeared first on Big Nerd Ranch.

]]>

A Street Called Awesome

As developers, we love having quality tools like git, available to us.

Using git, we can easily navigate through all the code ever “committed” or added to a project throughout its history. We do this via git treeishes. Treeishes are git’s way of referencing commits and relations between commits. Treeishes can improve your workflow immensely if you’re a frequent git user.

In this post, we’ll cover some of the more basic treeishes and then work into the advanced ones, with some real-world examples.

The Basics

You’ll probably be familiar with the types of treeishes in this first section if you’ve ever used git before. The following section will cover some more advanced uses of treeishes that even long-time git users may not know about.

SHAs

Every commit in git is identified by its SHA — a unique hash. These hashes are pretty long (40 characters in fact), but git also allows you to reference any commit with any truncated version of its hash so long as the truncated portion is unique (generally, this means at least 5 characters long).

Branches, Remotes, and Tags

Branches, remotes, and tags are another kind of treeish. Each of these is actually just a pointer to a git commit.

Advanced Treeishes

Now we’re getting to the really good stuff!

It’s important to have a good understand of the git reference log (reflog for short) which enables most of the more advanced treeishes.

The git reflog is a running log of recent changes to tips of branches. In practice, this means that every time you commit to a branch, pull commits down from a remote repository, or checkout a new branch, your reflog will update. It’s important to recall that reflogs are specific to individual checkouts of a repository so the reflogs for the same project can differ across machines.

Here’s an example reflog from one of my personal projects:

› git reflog
0a4faaa HEAD@{0}: checkout: moving from 0a4faaaf0081e2a5e439e79f48e236cdfbcb687b to i-herd-u-liek-chef
0a4faaa HEAD@{1}: commit: Remove unnecessary comment.
d4fdbdb HEAD@{2}: commit: Real namespaces in the app code now.
fc16081 HEAD@{3}: commit: Suddenly, NAMESPACES
b36e3a8 HEAD@{4}: clone: from git@github.com:wfarr/censored.git

This reflog shows that some of the more recent changes to this project include:

  • Cloning the project from the remote repository
  • Making a few commits
  • Checking out a new branch from the tree at 0a4faaa (which just happens to be master)

Using the reflog, git can infer some interesting relative context for commits that will allow us some more flexibility in what we can get at with treeishes.

Date Specs

We use the date spec here at Highgroove as part of our weekly code reviews. With the date spec, I can easily look at the activity on a feature branch over the course of the last week:

git diff master@{1 week ago}

Tilde Spec

Similar to the ordinal spec, the tilde spec allows you to reference the Nth grandparent of a commit.

This is useful just to go back 2 or more commits in time in one command.

master~2

Caret Parent Spec

Unlike the tilde spec, the caret parent spec allows you to reference the Nth parent of a commit. The distinction here is important as the caret parent spec can walk backwards through commits that have more than one parent (merge commits), while the ordinal spec cannot.

The caret parent spec looks like:

master^2

The caret parent spec and the tilde spec can also be chained together, so master^^ would actually point to the same commit as master~2.

Range Spec

The range spec allows you to express a range of commits as a first-class object in git. These are frequently used for things like diffs where you may want to view the changes across a number of commits.

For example, the following command would show a diff of all commits between master and my current feature branch:

git diff master..i-herd-u-liek-chef

You can also refer to the range from the current commit through all commits after it by just leaving off the other ref after the “..”.

All of these treeishes are available from the git command line interface – though if you’re using a GUI to interact with git your particular application it may support some or all of these. I know that Github’s compare view can be used with treeishes as well. Hopefully if you’re not already using treeishes you’ll find that they’re as useful to you as they are to us.

How are you using git treeishes to improve your workflow?

Image credit: @moonlightbulb

The post Git Treeishes Considered Awesome appeared first on Big Nerd Ranch.

]]>
https://bignerdranch.com/blog/git-treeishes-considered-awesome/feed/ 0
Getting into the Groove https://bignerdranch.com/blog/getting-into-the-groove/ https://bignerdranch.com/blog/getting-into-the-groove/#respond Sun, 15 Jan 2012 12:00:00 +0000 https://nerdranchighq.wpengine.com/blog/getting-into-the-groove/

Comando Groovy @ 2º Aniversario Radio Mexiquense 91.7 FM

The post Getting into the Groove appeared first on Big Nerd Ranch.

]]>

Comando Groovy @ 2º Aniversario Radio Mexiquense 91.7 FM

Going in to my third week here at Highgroove, I already feel like my first couple weeks have been some of my best in any work environment, both in terms of my personal productivity and my happiness at work.

I’m still completing my undergraduate degree at Georgia Tech. As any student at Tech will be quick to tell you, the school is often very demanding of its students. This can often make a good balance between work and school difficult, and juggling the two over the past couple years of school has been challening.

Enter Highgroove, a ROWE (Results-Only Work Environment).

I’ve been lucky enough to call a good portion of the Highgroove staff friends for a while, and I’d known that Highgroove works on amazing projects with even more amazing clients. This was more than enough to get me excited to work with Highgroove. But hearing more about how Highgroove is a ROWE during my interview process really interested me.

A ROWE sounds pretty self-explanatory — it’s all about results. Focusing on results rather than time spent “working” (who hasn’t checked on Reddit at work before?), allows us to work in a fashion that’s all about personal responsibility and trust. I can take a day to study for a big exam if I know I’ll have some time later on in the iteration to make sure I’m hitting my results. Reading the ROWE book (ironically, the one requirement we have at Highgroove besides meeting results) and working in a ROWE has already taught me a lot: mostly I don’t think I could go back to working any other way.

Highgroove gives me control over my time and allows me to focus on getting things done — whether for work, school, or me — in a completely guilt-free environment. And I’m loving every minute of it.

The post Getting into the Groove appeared first on Big Nerd Ranch.

]]>
https://bignerdranch.com/blog/getting-into-the-groove/feed/ 0