Use a command like:

git diff file_2.rb

See the git diff documentation for full information on the kinds of things you can get differences for.

Normally, git diff by itself shows all the changes in the whole repository (not just the current directory).

Answer from Greg Hewgill on Stack Overflow
๐ŸŒ
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
3 days ago - The git diff command helps you see, compare, and understand changes in your project. You can use it in many different situations, e.g. to look at current changes in your working copy, past changes in commits, or even to compare branches.
Discussions

What command can view who changed specific line of a file?
You probably want: git blame $filename This will output the file with each line annotated with the commit hash, date and author at which the line was last changed. This uses the same logic that git diff uses to calculate diffs. (Remember, Git does not directly store changes; it calculates changes on the fly as required.) You can provide extra options to see the file as of a particular commit, or to ignore certain uninteresting changes. More on reddit.com
๐ŸŒ r/git
4
4
May 9, 2021
How can I see what has changed in a file before committing to git? - Stack Overflow
I've noticed that while working on one or two tickets, if I step away, I'm not sure what I worked on, what changed, etcetera. Is there a way to see the changes made for a given file before git add... More on stackoverflow.com
๐ŸŒ stackoverflow.com
git log - View the change history of a file using Git versioning - Stack Overflow
Using git log --follow -p bar will show the file's entire history, including any changes to the file when it was known as foo. The -p option ensures that diffs are included for each change. ... I agree this is the REAL answer. (1.) --follow ensures that you see file renames (2.) -p ensures that you see how the file gets changed (3.) it is command ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Is there a way to use 'git show' on staged changes?
Found an answer! Leaving this up in case others stumble upon it https://stackoverflow.com/questions/5153199/git-show-content-of-file-as-it-will-look-like-after-committing More on reddit.com
๐ŸŒ r/git
4
6
July 28, 2022
๐ŸŒ
Graphite
graphite.com โ€บ guides โ€บ git-view-changes
How to view changes in Git - Graphite
This guide will explore the different methods to view changes in Git, using commands like `git diff`, `git status`, and others.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ git โ€บ how-to-view-the-change-history-of-a-file-using-git-versioning
Tracking File Changes Using Git - GeeksforGeeks
January 16, 2026 - Git will only show list of commits that affected the specified file. To view the changes that were made in a particular commit, we can use the git show command.
๐ŸŒ
Git Tower
git-tower.com โ€บ learn โ€บ git โ€บ ebook โ€บ en โ€บ command-line โ€บ advanced-topics โ€บ diffs
Inspecting Changes with Diffs | Learn Git Ebook (CLI Edition)
Without further options, "git diff" will show us all current local changes in our working copy that are unstaged. If you want to see only changes that have already been added to the Staging Area, "git diff --staged" is your command of choice.
๐ŸŒ
Opensource.com
opensource.com โ€บ article โ€บ 21 โ€บ 4 โ€บ git-whatchanged
Find what changed in a Git commit | Opensource.com
And this means you're aware of ... easier than you think. ... To find out which files changed in a given commit, use the git log --raw command....
Find elsewhere
๐ŸŒ
Tosbourn
tosbourn.com โ€บ articles โ€บ web dev โ€บ git command to show files changed in a commit
Git command to show files changed in a commit - Tosbourn
Review of Tosbourn Ltd.
Recently I wanted to pull a list of changed files from an older commit from the command line. There are lots of reasons why you would want to do this after the fact, and you donโ€™t always have access to tools like Github to see things visually. Toby had helped shape the digital team practice around Agile and ways of working on multidisciplinary teams, which was new to a lot of folks. I only heard great feedback about people's experience working with Toby - how inspiring and humble he is as a leader.
Rating: 5 โ€‹
๐ŸŒ
DEV Community
dev.to โ€บ shehrozirfan โ€บ git-commands-to-get-information-about-changes-made-to-your-files-4ge9
Git commands to get information about changes made to your files - DEV Community
February 5, 2022 - To see the actual lines changed in a specific commit you can use git show command. The git show command takes the commit id and then shows the files changed in that commit. You can get the commit id of a specific commit by using git log.
๐ŸŒ
Team Treehouse
teamtreehouse.com โ€บ library โ€บ introduction-to-git โ€บ viewing-changes-to-a-file
Viewing Changes to a File (How To) | Introduction to Git | Treehouse
Open up medals.html, and at the top add a level 1 heading: <h1>Welcome to our store!</h1>. Also add a descriptive paragraph: <p>Please choose a section below.</p> Once the file is saved, we can use the git diff command to view those changes.
Published ย  March 29, 2018
๐ŸŒ
Git
git-scm.com โ€บ book โ€บ en โ€บ v2 โ€บ Git-Basics-Recording-Changes-to-the-Repository
2.2 Git Basics - Recording Changes to the Repository
If you want to see what youโ€™ve staged that will go into your next commit, you can use git diff --staged. This command compares your staged changes to your last commit: $ git diff --staged diff --git a/README b/README new file mode 100644 index 0000000..03902a1 --- /dev/null +++ b/README @@ -0,0 +1 @@ +My Project
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ git โ€บ view the change history of a single file in git
View the change history of a single file in Git | Sentry
David Y. โ€” September 15, 2023 jump to solution ยท How can I see the change history of a single file in my Git repository? We can show the full change history of a file, taking renames into account, using the git log command:
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ git-diff-command
Git diff Command โ€“ How to Compare Changes in Your Code
March 29, 2022 - Perhaps you want to see the differences between two branches, commits, or files. These are common issues and tasks when working with a version control system. Fortunately, you can verify all this using the Git diff command...
๐ŸŒ
Smartprogramming
smartprogramming.in โ€บ tutorials โ€บ git-and-github โ€บ git-diff
git diff - Viewing Differences in Git
Learn how to use the git diff command to view differences in files, compare changes, and track modifications in your Git repository. Enhance your Git skills with practical examples.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ git-how-to-check-if-a-file-has-changes-in-git-560022
How to Check If a File Has Changes in Git | LabEx
Learn how to check for changes in Git using `git status` and `git diff`. Identify modified files and inspect line-by-line differences in your Git repository with this hands-on lab.
๐ŸŒ
Refine
refine.dev โ€บ home โ€บ blog โ€บ engineering โ€บ git diff - comparing changes in git
git diff - Comparing Changes in Git | Refine
July 30, 2024 - Let's unravel git diff's mysteries! 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.
Top answer
1 of 16
3115

This lets Git generate the patches for each log entry:

git log -p -- <filename>

-p in git generates patch text

See git help log for more options โ€” it can actually do a lot of nice things. :)


To get just the diff for a specific commit, use

git show <revision> -- <filename>

or specify any other revision by identifier.


To browse the changes visually:

gitk -- <filename>

To see changes visually without leaving the console, run:

git blame-log <filename>

However, first ensure blame-log command exists, by at least once running:

# Virables: raw=unchanged-line, c=clean, B=Buffer,
git config --global alias.blame-log "! cd -- \"\${GIT_PREFIX:-.}\" && \
( if git grep -qI \".\" \"\$1\"; then \
    git log --oneline --color=always -L 1,\${2:-}:\"\$1\" | awk ' \
    { s=\$0; gsub(/\\033\\[[0-9;]*[mK]/, \"\", s) } \
    s~/^(diff|---|\\+\\+\+)/{next} \
    s~/^@@/{l=1;p=9;bi=0;cm=0;cp=0;next} s!~/^[-+ ]/{print;l=1;p=9;bi=0;cm=0;cp=0;next} \
    /^ /{ cm=0;cp=0; if(p<3){print;p++}else{b[bi%3]=\$0; bl[bi%3]=l; bi++} l++; next } \
    { if(p>=3){ n=(bi<3?bi:3); st=(bi<3?0:bi%3); print \"\\033[36mLine \"(n?bl[st]:l)\":\\033[m\"; for(k=0;k<n;k++)print b[(st+k)%3] } \
      p=0; if(s~/^-/){cm++;if(cm<=12)print;else if(cm==13)print\"...\"} else{cp++;if(cp<=12)print;else if(cp==13)print\"...\";l++} }'; \
else \
    echo \"Detected binary file, hence not showing lines-changed.\"
    git log --oneline --color=always \"\$1\";
fi ) | less -RX #"

Note that blame-log is intentionally limited to showing few lines per change-range, for example, to skip package-lock.json faster.

2 of 16
2730

For a graphical view, use gitk:

gitk [filename]

To follow the file across file renames:

gitk --follow [filename]

For a console view, maybe because you SSH into a head-less server, run:

git blame-log <filename>

However, first ensure blame-log command exists, by at least once running:

# Virables: raw=unchanged-line, c=clean, B=Buffer,
git config --global alias.blame-log "! cd -- \"\${GIT_PREFIX:-.}\" && \
( if git grep -qI \".\" \"\$1\"; then \
    git log --oneline --color=always -L 1,\${2:-}:\"\$1\" | awk ' \
    { s=\$0; gsub(/\\033\\[[0-9;]*[mK]/, \"\", s) } \
    s~/^(diff|---|\\+\\+\+)/{next} \
    s~/^@@/{l=1;p=9;bi=0;cm=0;cp=0;next} s!~/^[-+ ]/{print;l=1;p=9;bi=0;cm=0;cp=0;next} \
    /^ /{ cm=0;cp=0; if(p<3){print;p++}else{b[bi%3]=\$0; bl[bi%3]=l; bi++} l++; next } \
    { if(p>=3){ n=(bi<3?bi:3); st=(bi<3?0:bi%3); print \"\\033[36mLine \"(n?bl[st]:l)\":\\033[m\"; for(k=0;k<n;k++)print b[(st+k)%3] } \
      p=0; if(s~/^-/){cm++;if(cm<=12)print;else if(cm==13)print\"...\"} else{cp++;if(cp<=12)print;else if(cp==13)print\"...\";l++} }'; \
else \
    echo \"Detected binary file, hence not showing lines-changed.\"
    git log --oneline --color=always \"\$1\";
fi ) | less -RX #"

Note that blame-log is intentionally limited to showing few lines per change-range, for example, to skip package-lock.json faster.

๐ŸŒ
Git
git-scm.com โ€บ docs โ€บ git-diff
Git - git-diff Documentation
I.e., -M5 becomes 0.5, and is thus ... to exact renames, use -M100%. The default similarity index is 50%. ... Detect copies as well as renames. See also --find-copies-harder. If <n> is specified, it has the same meaning as for -M<n>. ... For performance reasons, by default, -C option finds copies only if the original file of the copy was modified in the same changeset. This flag makes the command inspect unmodified ...
๐ŸŒ
OpenReplay
blog.openreplay.com โ€บ openreplay blog โ€บ how to identify modified files after a git commit
How to Identify Modified Files After a Git Commit
March 4, 2025 - Use git show --name-only to see modified files in the last commit. Use git log -1 --stat for a summary of modified files and changes.