To see how one tracked file differs from an earlier version in a Git repository on your Mac, open Terminal, move to the repository, and run git diff REVISION -- path/to/file. Replace REVISION with a commit such as HEAD~1 and the path with the file’s repository-relative path. This compares that committed version with the file as it exists in your working tree now; it does not change the file.
Open Terminal in the Repository
In Finder, locate the repository folder. Open Terminal, type cd with a trailing space, drag the repository folder into the Terminal window, then press Return. Apple documents dragging items into Terminal as a way to specify file and folder paths. Check that you are in a Git working tree with:
git status
If Git reports that the current directory is not a repository, change to the repository’s top-level folder and try again. Terminal uses zsh by default on macOS, according to Apple. The commands below work in that shell; they use quoted paths so spaces in names are preserved.
Compare the Current File with an Earlier Revision
Use this form:
git diff REVISION -- "path/to/file"
For example, to compare the current Sources/Menu.swift file with its version one first-parent commit before the current HEAD, run:
git diff 'HEAD~1' -- "Sources/Menu.swift"
The -- marks the end of revision and option arguments and the start of the path. Git documents this form as comparing the working tree with the named commit. In the output, lines beginning with - are from the earlier version, + lines are from the current file, and surrounding unmarked lines provide context. Git diff documentation
HEAD~1 means the first parent of the current commit; HEAD~2 follows two first-parent steps. This is handy for recent history, but it may not identify the exact change you have in mind, especially around merges. Git’s revision syntax also accepts branch names, tags, and commit IDs. Use a commit you have identified when you need a specific historical point. Git revision syntax
To find a commit that changed the file, inspect its history:
git log --oneline -- "Sources/Menu.swift"
Copy the relevant commit ID from the output, then use it in the diff command:
git diff 4f2a9c1 -- "Sources/Menu.swift"
Replace 4f2a9c1 with the actual ID shown in your repository. Git accepts an unambiguous abbreviated commit ID; if it is ambiguous or invalid, use a longer ID or another revision name.
Choose the Comparison That Matches Your Question
A working-tree comparison includes any current edits to the file, whether staged or unstaged. If instead you want to compare two committed versions, provide both revisions:
git diff OLD_REV NEW_REV -- "Sources/Menu.swift"
For example, git diff 'HEAD~3' HEAD -- "Sources/Menu.swift" compares the committed file three first-parent steps back with the version at the current commit. This does not include uncommitted edits. Git describes the two-commit form as comparing two arbitrary commits. Git diff documentation
If you want to compare against the version staged for the next commit, Git’s --cached form compares the index with a commit. For example:
git diff --cached HEAD -- "Sources/Menu.swift"
That answers a different question from comparing the current working file: it shows staged changes relative to HEAD.
Read Empty Output and Common Errors
No diff output usually means Git sees no difference for that path between the chosen revision and the selected current state. Confirm the path spelling and capitalization, and make sure you are inside the right repository. If Git says the path is unknown at the revision, that file may not have existed yet, or the path may have changed. To inspect a renamed or deleted file, use its historical path and check the relevant commit’s file list or log.
A file that Git has never tracked has no committed version to compare with. Also, Git’s ordinary text diff may not provide a readable line-by-line comparison for binary files. The command displays changes; it does not restore the old version. Avoid git checkout or git restore when your goal is only to inspect, because those commands have different effects on files.
For a narrower review, add a small context count, such as git diff -U1 'HEAD~1' -- "Sources/Menu.swift". Git’s -U option controls how many surrounding context lines appear. Once you have the desired revision and path, this command provides a direct, repeatable view of what differs while leaving your file untouched.
Sources
Change the default shell in Terminal on Mac — Apple Support
Drag items into a Terminal Window — Apple Support