Getting Git

A comprehensive video course from git init to Git Master.

init: git diff

In this video we'll learn how to use git diff.

git diff can be used for viewing current changes, but also historical changes.

Let's demonstrate this by making some changes to File 2.

When I run git diff I'll see these changes.

Any additions are show as plus lines (in green) and any deletions are shown as minus lines (in red).

Similar to git log I can use the arrows keys to scroll through the changes and at any time I can type q to quit.

It's important to note that git diff only displays changes to modified files.

That doesn't include changes to untracked or staged files.

Let's demonstrate this adding a timestamp to a new file.

If we run git diff we'll see the same output as before.

If we add this file with git add and run git diff we'll also see the same output.

That's because the new file is now staged. We can verify this with git status.

If I wanted to see the staged changes, I can use the --staged option.

For example:

git diff --staged

Shows me the changes to be committed in new file we created.

You could also pass git diff a file to limit its output to only the changes in that file.

For example:

git diff file-2.txt