Frequently you may want to easily see what has been changed as you’re working. Perhaps you just went out for a bite to eat and temporarily forgot, or maybe you need to check to see just what will be added into your newest commit. There’s a few Git commands that can help with this and make it very easy to figure out what has been modified.
Probably the easiest option is doing a
git diff. It will print out the lines that have changed in your working directory compared to what’s stored in
HEAD. So changing just one line in a README file would give me this output:
Provided your color options are turned on, it should be really easy to see what lines have been added, changed, or removed. There’s tons of other options for this command, but we’ll cover them and the other diff related helpers in future tips.
git diff will compare what is in the staging area and what’s last been committed. However, you may want to see what files were modified in the last commit. You could play around with the various logging options, or use
git whatchanged. This shortcut brings in the commit message, author information, and prints out exactly what files were touched for that changeset. So, if you wanted to see what the last commit changed:
$ git whatchanged -n 1 commit 698192122d725da2bc79f273571d91dba8b645a8 Author: Nick Quaranto <firstname.lastname@example.org> 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... M test/test_post.rb :100644 100644 03bf166... 7bcf6de... M test/test_site.rb
Of course, plenty of other options exist for this command at its manpage. If you have good ideas or ways to figure out what has changed in your repository from commit to commit, let us know!