Git diff --name-only and copy that list
zip update.zip $(git diff --name-only commit commit)
Here's a one-liner:
List changed files & pack them as *.zip:
git diff --name-only | zip patched.zip -@
List last committed changed files & pack them as *.zip:
git diff --name-only HEAD~ HEAD | zip patched.zip -@
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
-z
to withgit diff --name-only
means to output the list of files separated with NUL bytes instead of newlines, just in case your filenames have unusual characters in them.The
-0
toxargs
says to interpret standard input as a NUL-separated list of parameters.The
-IREPLACE
is needed since by defaultxargs
would append the parameters to the end of thersync
command. Instead, that says to put them where the laterREPLACE
is. (That's a nice tip from this Server Fault answer.)The
-a
parameter torsync
means to preserve permissions, ownership, etc. if possible. The-R
means 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
.)
Try the following command, which I have tested:
$ cp -pv --parents $(git diff --name-only) DESTINATION-DIRECTORY