From the git-diff manpage:

git diff [--options] <commit> <commit> [--] [<path>...]

For instance, to see the difference for a file "main.c" between now and two commits back, here are three equivalent commands:

$ git diff HEAD^^ HEAD main.c
$ git diff HEAD^^..HEAD -- main.c
$ git diff HEAD~2 HEAD -- main.c
Answer from mipadi on Stack Overflow
๐ŸŒ
Git
git-scm.com โ€บ docs โ€บ git-diff
Git - git-diff Documentation
Useful for commands like git show that show the patch by default to squelch their output, or to cancel the effect of options like --patch, --stat earlier on the command line in an alias. ... Generate diffs with <n> lines of context. The number of context lines defaults to diff.context or 3 if the configuration variable is unset. (-U without <n> is silently accepted as a synonym for -p due to a historical accident). Implies --patch. ... Output to a specific file instead of stdout.
Discussions

How do I view file differences (not commits) between two branches in git?
If I compare the branches I get different results depending on which order I choose them. I am curious as to the exact command you ran. git diff branch-a branch-b and: git diff branch-b branch-a should produce exactly the same output, just with + and - reversed. More on reddit.com
๐ŸŒ r/git
10
3
August 16, 2021
do a git diff which simply compares the files of one commit with those of another
Can you show what output_diff.txt looks like? More on reddit.com
๐ŸŒ r/git
5
1
March 12, 2025
How do you create a diff file with all of the uncommitted changes?
git diff by default tells you the difference between staged and unstaged changes. If you need to see the difference between uncommitted (both staged and unstaged) and the most recent commit, you can git diff HEAD. For your case, try git diff --minimal HEAD >> diff.txt. The minimal flag will help make it more readable, and the >> diff.txt will put the output in a file called diff.txt that you can send to your coworker More on reddit.com
๐ŸŒ r/git
2
2
June 19, 2019
Basic question - Does 'git diff' only show the difference between the two existing files
Git is not aware of files that are not tracked yet. If you created a new file, it is not tracked yet, until you add the file. However, that might be impractical for some cases, as this one, or if you want to stage only parts of an untracked file for example (e.g. with git add -p file). There is a flag named -N (or --intent-to-add) for git add, so that Git will become aware of the file, without actually adding the file: git add -N some-file git diff I made an initial empty commit IMO that is good practice, allows you to rebase more easily in the initial phase, where things are not too stable yet - keep it up! Though that is not relevant to your actual issue. More on reddit.com
๐ŸŒ r/git
9
11
December 22, 2018
๐ŸŒ
Git Tower
git-tower.com โ€บ learn โ€บ git faq โ€บ git diff - inspecting changes in git
Git Diff - Inspecting Changes in Git | Learn Version Control with Git
5 days ago - Running the plain git diff command without any parameters can be pretty helpful: it will show you all of your local changes since you last committed. ... Often, you'll want to see only the changes in a certain file.
๐ŸŒ
Refine
refine.dev โ€บ home โ€บ blog โ€บ engineering โ€บ git diff - comparing changes in git
git diff - Comparing Changes in Git | Refine
July 30, 2024 - The git diff command shows the code changes between two commits or between the current repository and an earlier commit. This command displays changes indicated by file headers and metadata for changed files.
Find elsewhere
๐ŸŒ
CloudBees
cloudbees.com โ€บ blog โ€บ git-diff-a-complete-comparison-tutorial-for-git
Git Diff: A Complete Comparison Tutorial for Git
September 14, 2021 - The output of git diff can be pretty overwhelming at first. For now, letโ€™s focus on the basics: Git is comparing two versions of the same file (a/file.txt and b/file.txt).
๐ŸŒ
Atlassian
atlassian.com โ€บ git โ€บ tutorials โ€บ saving changes โ€บ git diff
Git Diff | Atlassian Git Tutorial
Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ git โ€บ git-diff
Git diff - GeeksforGeeks
May 7, 2026 - git diff is a Git command used to compare changes between different states of a repository, helping developers see what has been modified in files before committing or merging.
๐ŸŒ
DEV Community
dev.to โ€บ nickfun โ€บ using-git-diff-and-git-apply-to-share-small-changes-3c0e
Using "git diff" and "git apply" to share small changes. - DEV Community
September 9, 2022 - Another option is to put the contents into a file and point git apply to that. Say you paste the diff into new.patch, you can apply the changes with:
๐ŸŒ
Git
git-scm.com โ€บ docs โ€บ git-diff-files
Git - git-diff-files Documentation
Useful for commands like git show that show the patch by default to squelch their output, or to cancel the effect of options like --patch, --stat earlier on the command line in an alias. ... Generate diffs with <n> lines of context. The number of context lines defaults to diff.context or 3 if the configuration variable is unset. (-U without <n> is silently accepted as a synonym for -p due to a historical accident). Implies --patch. ... Output to a specific file instead of stdout.
๐ŸŒ
Reddit
reddit.com โ€บ r/git โ€บ do a git diff which simply compares the files of one commit with those of another
r/git on Reddit: do a git diff which simply compares the files of one commit with those of another
March 12, 2025 -

I thought I was beginning to understand git diff.

But today I did a git diff between a commit at the tip of one branch ("A") with a commit at the tip of another ("B"), where tip of B is the newer commit. Thus I'm doing this:

> git diff [sha of tip of A] [sha of tip of B] > output_diff.txt

I'm quite baffled by the results, and in particular by the fact that lines which are present in neither commit's version of a given file (call it xxx.py) are included in the diff, with "++" at the start of the line.

These are all lines which **were** in branch A in the version of that file at one point ... but were then DELETED before the branch A tip commit was made. I'm baffled as to why these are there. They are of no interest to me, and make the diff file all the more difficult to understand.

Is there any way to just exclude these lines when doing a git diff?

๐ŸŒ
YouTube
youtube.com โ€บ watch
git diff: everything you need to know
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
๐ŸŒ
GitClear
gitclear.com โ€บ rich_diff_checker
Diff Checker - GitClear
The Rich Diff Checker finds the true differences between any two text files or code files by classifying changes using the full set of operations that developers recognize:
๐ŸŒ
Stefan Judis
stefanjudis.com โ€บ snippets โ€บ how-to-use-gits-file-diff-outside-of-git-repositories
How to use git's file diff outside of git repositories | Stefan Judis Web Development
October 18, 2020 - function diff() { if [ "$#" -ne 2 ]; then command diff "$@" return fi git diff --no-index $1 $2; } See below how my new diff fileA fileB command looks like now!
๐ŸŒ
KodeKloud
kodekloud.com โ€บ blog โ€บ git-diff-how-to-compare-files-between-two-branches
Git Diff: How to Compare Files Between Two Branches
November 27, 2025 - This becomes especially important when merging or integrating changes from one branch into another. The git diff command provides a clear and concise way to view the discrepancies in file content between different branches.
๐ŸŒ
Linux Kernel
kernel.org โ€บ pub โ€บ software โ€บ scm โ€บ git โ€บ docs โ€บ git-diff-files.html
git-diff-files(1)
June 20, 2025 - Useful for commands like git show that show the patch by default to squelch their output, or to cancel the effect of options like --patch, --stat earlier on the command line in an alias. ... Generate diffs with <n> lines of context. The number of context lines defaults to diff.context or 3 if the configuration variable is unset. (-U without <n> is silently accepted as a synonym for -p due to a historical accident). Implies --patch. ... Output to a specific file instead of stdout.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ git-diff-command
Git diff Command โ€“ How to Compare Changes in Your Code
March 29, 2022 - You can run git diff <commit_hash> <commit_hash> the command to compare the changes between two commits. Like branch comparison, order does matter in comparing commits. You can run the below commands to compare the changes for specific file:
๐ŸŒ
DEV Community
dev.to โ€บ jennieji โ€บ how-to-read-a-raw-git-diff-1pl2
Git diff explained - DEV Community
May 30, 2020 - Each "diff" block contains the changes of one file, and starts with line: diff --git a/relative_file_path b/relative_file_path
๐ŸŒ
Scott Willsey
scottwillsey.com โ€บ gitcommitdiffs
Git Diff With Previous Commit Versions
June 13, 2023 - git difftool 5298935609b106365c2786a711c844395539a43d cfcbb396fb29e1e100908152f002ae2f9f6d3f29 package.json ยท Then your difftool of choice opens and you can compare the two versions of the same file from two different commits side by side:
๐ŸŒ
Packetcoders
packetcoders.io โ€บ how-to-use-git-diff-to-compare-changes-between-commits-and-branches
How to Use Git Diff to Compare Changes Between Commits and Branches
October 4, 2024 - # Compare Changes Between Commits git diff <commit1> <commit2> # Compare changes between two commits. git diff <commit1> <commit2> -- <path/to/file> # Compare changes for a specific file between two commits. # Compare Changes Between Branches git diff <branch1> <branch2> # Compare changes between two branches.