Git diff --name-only and copy that list

后端 未结 7 737
眼角桃花
眼角桃花 2021-01-29 18:55

I just want to get a list of changed files between two revisions, which is simple:

git diff -–name-only commit1 commit2 > /path/to/my/file

B

相关标签:
7条回答
  • 2021-01-29 19:06

    It works perfectly.

    git diff 1526043 82a4f7d --name-only | xargs zip update.zip
    
    git diff 1526043 82a4f7d --name-only |xargs -n 10 zip update.zip
    
    0 讨论(0)
  • No-one has mentioned cpio which is easy to type, creates hard links and handles spaces in filenames:

    git diff --name-only $from..$to  | cpio -pld outdir
    
    0 讨论(0)
  • 2021-01-29 19:13
    zip update.zip $(git diff --name-only commit commit)
    
    0 讨论(0)
  • 2021-01-29 19:21

    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 with git 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 to xargs says to interpret standard input as a NUL-separated list of parameters.

    • The -IREPLACE is needed since by default xargs would append the parameters to the end of the rsync command. Instead, that says to put them where the later REPLACE is. (That's a nice tip from this Server Fault answer.)

    • The -a parameter to rsync 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.)

    0 讨论(0)
  • 2021-01-29 19:31

    Try the following command, which I have tested:

    $ cp -pv --parents $(git diff --name-only) DESTINATION-DIRECTORY
    
    0 讨论(0)
  • 2021-01-29 19:31

    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 -@
    
    0 讨论(0)
提交回复
热议问题