shell 拷贝 git工程变化的文件,并保持原有目录结构

gitWork="./aaa"

cd $gitWork
git status -s > ../a.txt
cd ..

outpath="./out"
tempFile=""
findRes=""
while read line
do
  # 过滤
  findRes=$(echo $line | grep "^[^D?]")
  if [[ $findRes != "" ]]
    then
      # 测试匹配
      # echo $findRes
      tempFile=${line//M //}
      tempFile=${tempFile//A  //}

      # 测试复制文件
      #echo $tempFile
      # mkdir
      [ ! -d ${outpath}$(dirname ${tempFile}) ] && mkdir -p ${outpath}$(dirname ${tempFile})
      # copy
      cp -rf $gitWork$tempFile ${outpath}$(dirname ${tempFile})
  fi
done < ./a.txt

rm -rf ./a.txt