txw/script/copy-changed-files.sh

36 lines
754 B
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 复制 git 变更文件到 change 目录,保留原文件相对路径
set -e
TARGET_DIR="change"
# 创建目标目录
mkdir -p "$TARGET_DIR"
# 获取所有变更文件(包含未跟踪文件)
files=$(git status --porcelain | awk '{print $2}')
if [ -z "$files" ]; then
echo "没有变更文件"
exit 0
fi
count=0
for f in $files; do
# 跳过目录(如 docs/
if [ -d "$f" ]; then
mkdir -p "$TARGET_DIR/$f"
cp -r "$f" "$TARGET_DIR/$f"
echo "$f/"
elif [ -f "$f" ]; then
mkdir -p "$TARGET_DIR/$(dirname "$f")"
cp "$f" "$TARGET_DIR/$f"
echo "$f"
((count++))
fi
done
echo ""
echo "已完成,复制了 $count 个文件到 $TARGET_DIR 目录"