Try the following command, which I have tested:

$ cp -pv --parents $(git diff --name-only) DESTINATION-DIRECTORY
Answer from York on Stack Overflow
🌐
Reddit
reddit.com › r/git › name-only diff between branches shows changes, but regular diff for any specific file is empty
r/git on Reddit: name-only diff between branches shows changes, but regular diff for any specific file is empty
August 9, 2024 -

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?

Discussions

git diff --name-only and spaces
Hi I have a commit that includes several files One of them is a text file that i would like to commit as new instead of the previous one. This file has allot of changes from the previous version - ... More on github.com
🌐 github.com
1
1
git diff --name-only and spaces
I had to recover the set of files modified during a specific commit as follows: COMMIT=28cd71c36323b8ff4ff01cfabed0a1764d4744c3 git archive -o changed.zip $COMMIT $(git diff --name-only $COMMIT $CO... More on github.com
🌐 github.com
2
1
November 24, 2018
git - Magit diff with --name-only? - Emacs Stack Exchange
I am browsing the differences between two branches of a repository via git diff --name-only branch1 branch2 I also use the --name-status option sometimes, since I may need to see what sort of diff... More on emacs.stackexchange.com
🌐 emacs.stackexchange.com
December 5, 2017
Question: diff --name-only command implementation
Hey-hey, I tried to create following git command with go-git: git diff --name-only --diff-filter=AM HEAD~5 HEAD -- . At some point in my code I have a Patch and iterate over stats: patch, _ := last... More on github.com
🌐 github.com
10
November 1, 2018
🌐
Moakh
moakh.com › blog › git diff: only show filenames
Git Diff: Only Show Filenames | moakh
April 9, 2023 - It takes the same arguments as a regular git diff command, so if you only want the filenames of changed blog posts stored in a content/blog/ directory, you could do something like this: ... The --name-only flag also works with git show.
🌐
Better Stack
betterstack.com › community › questions › list-names-of-changed-files-between-commits
How to List Only the Names of Files That Changed between Two Commits | Better Stack Community
June 24, 2024 - To list only the names of files that changed between two commits in Git, you can use the git diff command with the --name-only option.
🌐
Git
git-scm.com › docs › git-diff
Git - git-diff Documentation
Omit diff output for unmerged entries and just show "Unmerged". Can be used only when comparing the working tree with the index. ... The <path> parameters, when given, are used to limit the diff to the named paths (you can give directory names and get diff for all files under them).
🌐
GitHub
github.com › orgs › community › discussions › 21723
git diff --name-only and spaces · community · Discussion #21723
As for the rest of the file commited - it will use the diff as it is ... Beta Was this translation helpful? Give feedback. ... Welcome to the Github Community Forum!
🌐
Explain Shell
explainshell.com › explain
explainshell.com - git diff --cached --name-only; git diff --name-only
git diff(1) distro · arch latest · ubuntu 26.04 --cached --name-only; git diff(1) distro · arch latest · ubuntu 26.04 --name-only ·
Find elsewhere
🌐
Linux Hint
linuxhint.com › list-only-the-names-files-that-changed-between-two-commits
How to List Only the Names of Files that Changed Between Two Commits – Linux Hint
To list only the names of files that changed between two commits, the “$ git diff --name-only ” command can be utilized.
🌐
Quora
quora.com › How-do-you-list-only-the-file-name-changes-between-two-commits-in-git
How to list only the file name changes between two commits in git - Quora
Answer (1 of 8): > How do you list only the file name changes between two commits in git? With git diff, the solution is straightforward: [code]git diff --name-only commitA commitB [/code]If I may read between the lines and guess that you actually want the commit identifiers listed, along with ...
🌐
Act-Show Linux
linuxactionshow.com › home › about linux › exploring git’s name-only differential comparison
Git Diff Name Only: Mastering - Act-Show Linux
September 26, 2023 - This allows for a comparison between two distinct commits, showcasing only the names of files that exhibit changes. The git diff –name-only command stands as an instrumental feature for Git users.
🌐
Git Scripts
gitscripts.com › git-diff-name-only
Understanding git diff --name-only for Quick Insights
September 11, 2025 - The `git diff --name-only` command lists only the names of files that have differences between the working directory and the staging area or between two commits, making it a useful tool for quickly identifying changed files.
🌐
Tsuji
tsuji.tech › home › posts › git
Git Diff with Only File Names | tsuji.tech
November 11, 2024 - Print git diff with only file names. git diff --name-only
🌐
Git Examples
gitexamples.com › examples › d4796b08-6044-43ff-a457-446124b4e252
git diff <commitA> --name-only
Show only the names of files that changed compared to a specific commit. This command is useful when you want a quick overview of which files changed relative to a given point in history, without being distracted by the full line-by-line diffs.
🌐
Makandra
makandracards.com › makandra › 15763-git-show-filenames-diff
Git: How to show only filenames for a diff - makandra dev
April 24, 2013 - Need a quick view of changed files without the full patch; git diff --name-only lists filenames, while --stat and --numstat add compact change counts.
🌐
GitHub
github.com › src-d › go-git › issues › 1014
Question: diff --name-only command implementation · Issue #1014 · src-d/go-git
November 1, 2018 - Hey-hey, I tried to create following git command with go-git: git diff --name-only --diff-filter=AM HEAD~5 HEAD -- . At some point in my code I have a Patch and iterate over stats: patch, _ := lastCommit.Patch(&firstCommit) for i := 0; i...
Author   src-d
🌐
Factorcode
docs.factorcode.org › content › word-git-diff-name-only__star__,cli.git.html
git-diff-name-only* ( from to -- lines ) - Factor Documentation
: git-diff-name-only* ( from to -- lines ) [ { "git" "diff" "--name-only" } ] 2dip 2array append process-lines ;