Skip to content
Andrew White edited this page Feb 11, 2014 · 1 revision

Who wrote this code?

If you see code you don't understand, sometimes it is helpful to see the commit message associated with the change. To do this, use the git blame command which will show the source file along with who made the last change to each line. For example:

$ git blame Rakefile
827a0fee (Xavier Noria           2011-08-27 03:55:01 -0700  1) require 'sdoc'
dff0dfb7 (Xavier Noria           2010-11-16 14:07:55 +0100  2) require 'net/http'
8922c5dc (Jeremy Kemper          2007-10-15 00:10:39 +0000  3) 
4ff8c59f (Carl Lerche            2010-11-16 15:42:39 -0800  4) $:.unshift File.expand_path('..', __FILE__)
4ff8c59f (Carl Lerche            2010-11-16 15:42:39 -0800  5) require "tasks/release"
7a5aa720 (Xavier Noria           2013-03-29 21:16:12 +0100  6) require 'railties/lib/rails/api/task'
4ff8c59f (Carl Lerche            2010-11-16 15:42:39 -0800  7) 
4ff8c59f (Carl Lerche            2010-11-16 15:42:39 -0800  8) desc "Build gem files for all projects"
4ff8c59f (Carl Lerche            2010-11-16 15:42:39 -0800  9) task :build => "all:build"
4ff8c59f (Carl Lerche            2010-11-16 15:42:39 -0800 10) 
67f66884 (Arun Agrawal           2013-06-21 10:57:00 +0200 11) desc "Release all gems to rubygems and create a tag"
c3dd1238 (Carl Lerche            2010-11-16 16:30:53 -0800 12) task :release => "all:release"

What was the commit message?

To see the commit message, use git show along with the hash. Let's look at Carl's commit from above with hash "4ff8c59f":

[aaron@higgins rails (master)]$ git show 4ff8c59f
commit 4ff8c59fb71de4d8d1c5066c73b110bce29e7aa5
Author: Carl Lerche <me@carllerche.com>
Date:   Tue Nov 16 15:42:39 2010 -0800

    Update the main Rakefile to use the new release tasks

diff --git a/Rakefile b/Rakefile
index a58d358..9da84ee 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,6 +5,15 @@ require 'rake'
 require 'rdoc/task'
 require 'net/http'
 
+$:.unshift File.expand_path('..', __FILE__)
+require "tasks/release"
+
+desc "Build gem files for all projects"
+task :build => "all:build"
+
+desc "Release all gems to gemcutter and create a tag"
+task :release => ["all:release", "git:tag"]
+
 # RDoc skips some files in the Rails tree due to its binary? predicate. This is a quick
 # hack for edge docs, until we decide which is the correct way to address this issue.
 # If not fixed in RDoc itself, via an option or something, we should probably move this
[aaron@higgins rails (master)]$

This shows the commit message along with the changes Carl made.

How do I go back in time?

In order to see what the Rakefile looked like before Carl's change, we can use the git checkout command along with the commit hash and a "^" character:

[aaron@higgins rails (master)]$ git checkout 4ff8c59f^
[aaron@higgins rails (fb5b2ba...)]$

This puts us on the commit right before Carl's change. Each "^" means "one previous commit", so git checkout 4ff8c59f^ means the commit before Carl's commit, where git checkout 4ff8c59f^^ means two commits, git checkout 4ff8c59f^^^ means three commits, etc.

Do git checkout master to get back to the master branch.

Viewing the commit on GitHub

Let's view Carl's commit on GitHub. To do that, just go to "https://github.com/rails/rails/commit/4ff8c59f". Just replace this hash with any hash you want to know about in the Rails project.