‘git diff’ doesn’t show enough

The important thing to realize about git diff A B is that it only ever shows you the difference between the states of the tree between exactly two points in the commit graph – it doesn’t care about the history. The .. and … notations used for git diff have the following meanings: So when … Read more

Generate diff file of a specific commit in Git

See the changes of a specific commit: git diff <commit-sha> -p Or, git show –decorate <commit-sha> # See ‘Author’, ‘Date’ and ‘diff’ See the diff of two commits: git diff <commit1> <commit2> See the file changes for a specific commit: git show <commit>:<file> See all the changes for a time duration (say, 1 day): git … Read more

Order of commit arguments in git diff

TL;DR In the following git-diff syntax, git diff [–options] <commit> <commit> [–] [<path>…] the first <commit> corresponds to the base commit, the second <commit> corresponds to the commit to compare to the base commit. Using a mathematically inspired notation, git diff <x> <x+∆x> will show you the difference ∆x, whereas git diff <x+∆x> <x> will … Read more

`git diff –stat` exclude certain files

The exclude pathspec trick, described in Making ‘git log’ ignore changes for certain paths, works here: git diff –stat — . ‘:(exclude)file/to/exclude.txt’ or, if you are in a subdirectory: git diff –stat — :/ ‘:(exclude,top)file/to/exclude.txt’ The latter can be spelled in various ways. For instance, this also works: git diff –stat ‘:(top)’ :!/file/to/exclude.txt as does: … Read more

How can I see the differences between two branches?

Use git diff. git diff [<options>] <commit>..​<commit> [–] [<path>…​] <commit> is a branch name, a commit hash, or a shorthand symbolic reference. Examples: git diff abc123..def567 git diff HEAD..origin/master That will produce the diff between the tips of the two branches. If you’d prefer to find the diff from their common ancestor to test, you … Read more