Pew Pew Laser Blog

Code. Glass art. Games. Baking. Cats. From Seattle, Washington and various sundry satellite locations.

Pew Pew Laser Blog Archives — by Blog ID

Git Tips - Diff.

2.22.2016

Let's talk about how to refer to previous commits absolutely using a hash/sha; or relative to your working directory, master, or previous commits.

Here's quick reference on some cool things you can do with Git's diff command:

git diff
The standard form of git diff will show all differences between your current working directory and the index (the files that Git is watching and has staged for your next commit).
git diff --cached
Just the differences that you've staged (files added to the index); what you would be committing if you run "git commit" without "-a" option.
git diff --name-only
Show just the names of files that are different between your working directory and the index (last commit). Or, pass in two hashes to compare files from those two commits.
git diff master --name-only
Show all files changed between master and your current working directory. This is great for reviewing what changed files you're actually going to commit.
git diff HEAD
Both staged and unstaged changes in your repo; what you would be committing if you run git commit -all.
git diff HEAD~1
Compare current files to the ones from the previous commit. Also git diff HEAD^ HEAD.
git diff HEAD master [file]
Show differences between the working directory and master for one file.
git diff [hash]
Diff between current and previous commit.

Note that hash is that long string which identifies a commit if you do git log.

Permalink

Tags: git

Authorized users may log-in to leave a comment.

Last Blog: How to Make a Pee-Wee Runt Rover with Johnny-Five.

Next Blog: Who to Send to Conferences.