Git Tips - Diff.
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
- The standard form of
git diffwill 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.
hash is that long string which identifies a commit if you do