Git - Compare two commits using git diff

This article covers how to use the command 'git init'.

If you want to see the differences between files in two different commits, or between a commit and your current repository, you can use git diff.

To run it, simply call git diff:

git diff

When called on its own, the command will display any changes made since you last committed.

To see changes in a specific file/directory

If you only want to see the changes made in a single file, or directory, you can supply the path:

git diff <file-path>

For example, I can look at the changes I've made in my working repository to the src/index.html file:

git diff src/index.html

using git diff 1


If you have already moved changes to the staging area, you can view these with the --staged parameter:

git diff --staged <file-path>


By default, git will show a change by displaying the original line in red, and the current edited line in green.

You may find it easier to view the individual character changes, using the --color-words parameter:

git diff --color-words <file-path>

For example:

git diff --color-words src/index.html

using git diff 1