2015-07-10 45 views

回答

3
  1. 創建名爲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"; 
    
  2. 運行腳本從你的Git項目的根目錄的命令:

    ./git-copy.sh git-hash-1 git-hash-2 path/to/destination/folder 
    

它將所有具有相同目錄結構的文件複製到t他目的地文件夾。

0

這裏是我寫的,這將複製文件的文件夾結構指定的提交哈希一個小的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 

創建一個文件名爲「〜/腳本/複印提交。 SH」然後給它執行特權:

chmod a+x ~/Scripts/copy-commit.sh 

然後,從git倉庫的根:

~/Scripts/copy-commit.sh COMMIT_KEY ~/Existing/Destination/Folder/ 

獲取最後一次提交哈希:

git rev-parse HEAD 
相關問題