Git diff --name-only and copy that list

后端 未结 7 739
眼角桃花
眼角桃花 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:32

    #!/bin/bash
    # Target directory
    TARGET=/target/directory/here
    
    for i in $(git diff --name-only)
        do
            # First create the target directory, if it doesn't exist.
            mkdir -p "$TARGET/$(dirname $i)"
            # Then copy over the file.
            cp -rf "$i" "$TARGET/$i"
        done
    

    https://stackoverflow.com/users/79061/sebastian-paaske-t%c3%b8rholm

提交回复
热议问题