Git diff command

We can use the git diff command to view changes between commits, branches, files, our working directory, and more!


git diff

The above command compares Staging Area and Working Directory and list it.


git diff HEAD

git diff HEAD lists all changes in the working tree since our last commit. As HEAD typically refers to the last commit.

Comparing Branches
The below command will list the changes between the tips of branch1 and branch2.


git diff branch1..branch2

Comparing Commits
To compare two commits, provide git diff with the commit hashes of the commits in question.


git diff commit1..commit2