travis1097 travis1097 - 1 year ago 83
Git Question

See diff between current state and last commit

Sometimes when I'm about to make a commit, I can't recall exactly what has changed since the last commit. How can I see a diff of the current state of the code and the last commit?

Answer Source

If you haven't added any files to the index yet (with git add), simply do

git diff

This will show the diff between your working tree and index.

If you have added files to the index, you need to do this to show the differences between index and the last commit (HEAD).

git diff --cached

Finally, if you want to see the changes made in the working tree compared to the latest commit (HEAD) you can (as Carlos points out) do

git diff HEAD

Those changes are the combination of git diff and git diff --cached.