Try the following command, which I have tested:
$ cp -pv --parents $(git diff --name-only) DESTINATION-DIRECTORY
Answer from York on Stack OverflowTry the following command, which I have tested:
$ cp -pv --parents $(git diff --name-only) DESTINATION-DIRECTORY
The following should work fine:
git diff -z --name-only commit1 commit2 | xargs -0 -IREPLACE rsync -aR REPLACE /home/changes/protected/
To explain further:
The
-zto withgit diff --name-onlymeans to output the list of files separated with NUL bytes instead of newlines, just in case your filenames have unusual characters in them.The
-0toxargssays to interpret standard input as a NUL-separated list of parameters.The
-IREPLACEis needed since by defaultxargswould append the parameters to the end of thersynccommand. Instead, that says to put them where the laterREPLACEis. (That's a nice tip from this Server Fault answer.)The
-aparameter torsyncmeans to preserve permissions, ownership, etc. if possible. The-Rmeans to use the full relative path when creating the files in the destination.
Update: if you have an old version of xargs, you'll need to use the -i option instead of -I. (The former is deprecated in later versions of findutils.)
git - How to list only the names of files that changed between two commits - Stack Overflow
Can I make 'git diff' only display the line numbers AND changed file names? - Stack Overflow
bash - Return list using git diff and grep - Unix & Linux Stack Exchange
name-only diff between branches shows changes, but regular diff for any specific file is empty
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 |
You 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.
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?