Git Show differences for a specific file or directory


Example

git diff myfile.txt

Shows the changes between the previous commit of the specified file (myfile.txt) and the locally-modified version that has not yet been staged.

This also works for directories:

git diff documentation

The above shows the changes between the previous commit of all files in the specified directory (documentation/) and the locally-modified versions of these files, that have not yet been staged.

To show the difference between some version of a file in a given commit and the local HEAD version you can specify the commit you want to compare against:

git diff 27fa75e myfile.txt

Or if you want to see the version between two separate commits:

git diff 27fa75e ada9b57 myfile.txt

To show the difference between the version specified by the hash ada9b57 and the latest commit on the branch my_branchname for only the relative directory called my_changed_directory/ you can do this:

git diff ada9b57 my_branchname my_changed_directory/