Git 复制上次提交时更改的所有文件

Git 复制上次提交时更改的所有文件,git,Git,如何导出上次提交中更改的所有文件 我是否可以只获取上次提交的文件列表是单独的文件夹 创建一个名为git copy.sh的文件,其内容如下: #!/bin/bash # Target directory TARGET=$3 echo "Finding and copying files and folders to $TARGET" for i in $(git diff --name-only $1 $2) do # First create the target dir

如何导出上次提交中更改的所有文件

我是否可以只获取上次提交的文件列表是单独的文件夹

  • 创建一个名为git copy.sh的文件,其内容如下:

    #!/bin/bash
    # Target directory
    TARGET=$3
    echo "Finding and copying files and folders to $TARGET"
    for i in $(git diff --name-only $1 $2)
        do
            # First create the target directory, if it doesn't exist.
            mkdir -p "$TARGET/$(dirname $i)"
             # Then copy over the file.
            cp "$i" "$TARGET/$i"
        done
    echo "Files copied to target directory";
    
  • 从git项目的根目录以命令形式运行脚本:

    ./git-copy.sh git-hash-1 git-hash-2 path/to/destination/folder
    
  • 它会将具有相同目录结构的所有文件复制到目标文件夹。

    下面是我编写的一个小bash(Unix)脚本,它将使用文件夹结构复制给定提交哈希的文件:

    ARRAY=($(git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $1))
    PWD=$(pwd)
    
    if [ -d "$2" ]; then
    
        for i in "${ARRAY[@]}"
        do
            : 
            cp --parents "$PWD/$i" $2
        done
    else
        echo "Chosen destination folder does not exist."
    fi
    
    创建名为“~/Scripts/copy commit.sh”的文件,然后授予其执行权限:

    chmod a+x ~/Scripts/copy-commit.sh
    
    然后,从git存储库的根目录:

    ~/Scripts/copy-commit.sh COMMIT_KEY ~/Existing/Destination/Folder/
    
    要获取最后一个提交哈希,请执行以下操作:

    git rev-parse HEAD
    

    我需要修改后的文件复制到相同的文件夹结构。如果文件名中有空格,有人能帮助我吗?@Spidey我找到了一个简单的解决方案。