You can use this command to see the changed file names, but not with line numbers:
git diff --name-only
Go forth and diff!
Answer from phreakhead on Stack OverflowYou can use this command to see the changed file names, but not with line numbers:
git diff --name-only
Go forth and diff!
Line numbers as in number of changed lines or the actual line numbers containing the changes? If you want the number of changed lines, use git diff --stat. This gives you a display like this:
[me@somehost:~/newsite:master]> git diff --stat
whatever/views/gallery.py | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
There is no option to get the line numbers of the changes themselves.
name-only diff between branches shows changes, but regular diff for any specific file is empty
git diff --name-only and spaces
git - Showing which files have changed between two revisions - Stack Overflow
git diff - How to show only filenames with "git status"? - Stack Overflow
git diff --name-only SHA1 SHA2
where you only need to include enough of the SHA hash to identify the commits. The order of the SHAs does not matter. The output (which includes the relative path, not just the file name) follows this format:
dir 1/dir 2/filename.ext
dir 3/dir 4/other filename.ext
You can also do, for example
git diff --name-only HEAD~10 HEAD~5
to see the differences between the tenth latest commit and the fifth latest (or so).
git diff --name-status [SHA1 [SHA2]]
is like --name-only, except you get a simple prefix telling you what happened to the file (modified, deleted, added...)
git log --name-status --oneline [SHA1..SHA2]
is similar, but commits are listed after the commit message, so you can see when a file was changed.
if you're interested in just what happened to certain files/folders you can append
-- <filename> [<filename>...]to thegit logversion.if you want to see what happened for a single commit, call it SHA1, then do
git log --name-status --oneline [SHA1^..SHA1]
File status flags:
| Flag | Name | Meaning |
|---|---|---|
M |
modified | File has been modified |
C |
copy-edit | File has been copied and modified |
R |
rename-edit | File has been renamed and modified |
A |
added | File has been added |
D |
deleted | File has been deleted |
U |
unmerged | File has conflicts after a merge |
Edit [Solved]: As per u/ppww's comment, I wasn't in the root directory of the repo, so my paths were invalid.
If I do the following command, I get a really long list of changed files. Most of which I expect, but some shouldn't have changed:
git diff --name-only myBranch1 myBranch2
For example, one of the files mentioned in the diff is src/general/Log.php
But if I use the following command to check the difference in that particular file, it just prints an empty line and exits the diff:
git diff myBranch1 myBranch2 -- src/general/Log.php
Trying to diff a directory instead of a file does the same thing.
I did however confirm that if I do a full diff across the two branches (not name-only) it does actually show the differences, but as there is a lot in there, most of which isn't what I'm looking for, it would be really tedious to view the whole diff.
What am I doing wrong?
To compare the current branch against main branch:
$ git diff --name-status main
To compare any two branches:
$ git diff --name-status firstbranch..yourBranchName
There are more options to git diff in the official documentation (and specifically the --name-status option).
Try
$ git diff --stat --color master..branchName
This will give you more info about each change, while still using the same number of lines.
You can also flip the branches to get an even clearer picture of the difference if you were to merge the other way:
$ git diff --stat --color branchName..master
There's an output option which does pretty much what you asked.
Only paths, with a letter to indicate A(dded), (M)odified, and so on.
git status -s [-b]
Instead of git status, use git diff, e.g.,
$ # Show modified, unstaged files, and only the filenames
$ git diff --name-only --diff-filter=u
my-file
$ # Show modified, staged/cached files, and only the filenames
$ git diff --name-only --diff-filter=u --cached
my-staged-file
Provide a path (myfolder in this case) and just run:
git diff myfolder/
If you're comparing different branches, you need to use -- to separate a Git revision from a filesystem path. For example, with two local branches, master and bryan-working:
git diff master -- AFolderOfCode/ bryan-working -- AFolderOfCode/
Or from a local branch to a remote:
git diff master -- AFolderOfCode/ origin/master -- AFolderOfCode/