git diff

Updated: 31 December 2023

Diff between branches

git diff branch1..branch2

which is equivalent to

git diff branch1 branch2

Diff of one file path

git diff branch1..branch2 -- myfile.cs

Diff of a directory between branches

git diff master..mybranch path/to/dir

Diff of one file between version in given commit and local HEAD

git diff 2f43f286 index.php

Show the number of lines changed

git diff --stat
git diff --numstat

Diff from a common ancestor

git diff [options] commitA...commitB [--] [path...]

This form is to view the changes on the branch containing and up to commitB, starting at a common ancestor of both commit

git diff A...B

is equivalent to

git diff $(git merge-base A B) B

Use separate tool (e.g. Meld) to view diff

git difftool --dir-diff branch1 branch2

Diff two directories not tracked by Git

git diff --no-index Downloads Downloads-copy

Highlight changed words using only colors

git diff --color-words

Generate diffs with n lines of context instead of the usual three

git diff --unified=0
git diff -U0

Show only names of changed files

git diff --name-only master media-coverage

Leave a comment