Sometimes, you may want to quickly see what changes have been made as you work. Perhaps you stepped away for a moment and need a refresher, or you want to review what will be included in your next commit. Fortunately, Git offers several commands to help with this, making it effortless to identify modifications.

One of the simplest options is git diff. It displays the lines that have changed in your working directory compared to what’s stored in HEAD. For instance, modifying just one line in a README file would produce output like this:

diff --git a/README.md b/README.md
index 1a2b3c4..5a6b7c8 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,3 @@
-Hello, World!
+Hello, Git!

Assuming your color options are enabled, it should be easy to spot the added, changed, or removed lines. While there are numerous other options for this command, we’ll explore them along with other diff-related helpers in future tips.

While git diff compares the staging area with the last commit, you may want to see which files were modified in the last commit. Instead of tinkering with various logging options, you can use git whatchanged. This shortcut provides the commit message, author information, and precisely lists the files touched in that changeset. So, if you wish to examine the last commit’s changes:

$ git whatchanged -n 1
  commit 698192122d725da2bc79f273571d91dba8b645a8
  Author: Nick Quaranto <nick@quaran.to>
  Date:   Wed Jan 28 09:22:46 2009 -0500

      Adding support for setting post categories through YAML 
      if not specified by directory structure

      :100644 100644 92e4ce1... de43f33... M  .gitignore
      :100644 100644 0706818... 81213b3... M  lib/jekyll/post.rb
      :100644 100644 9aabcdd... 611d6d6... M  test/helper.rb
      :100644 100644 56e5e42... 373545d... M  test/test_generated_site.rb
      :100644 100644 713eec0... 202ea55