git获取代码变更文件
获取变更日志的log
git log commit c4a851bcfdbea2fe8bd450254064771412291e3a (HEAD -> dev, origin/dev) Author: xxx Date: Wed Apr 22 17:37:31 2026 +0800 update route commit a834aeeecbd02261c5fde3f0d443e6eaa446be33 Author: xxx Date: Wed Apr 22 17:34:37 2026 +0800 Revert "without throttle" This reverts commit c5b3527e9615165e6f400701939d5280fab85cac. commit c5b3527e9615165e6f400701939d5280fab85cac (origin/dev-lottery-stock) Author: xxx :...skipping... commit c4a851bcfdbea2fe8bd450254064771412291e3a (HEAD -> dev, origin/dev) Author: xxx Date: Wed Apr 22 17:37:31 2026 +0800 update route
找到目标 commit 后,打包导出变更文件
# Windows PowerShell # 替换成你实际的新旧 commit hash $old = "a834aeeecbd02261c5fde3f0d443e6eaa446be33" $new = "c4a851bcfdbea2fe8bd450254064771412291e3a" # 打包成 zip git archive $new $(git diff --name-only $old $new) -o export.zip # Linux # 替换成你的 commit hash OLD_COMMIT="a834aeeecbd02261c5fde3f0d443e6eaa446be33" NEW_COMMIT="c4a851bcfdbea2fe8bd450254064771412291e3a" # 打包变更文件成 zip git archive $NEW_COMMIT $(git diff --name-only $OLD_COMMIT $NEW_COMMIT) -o export.zip使用临时文件(最稳妥)
$old = "ad336731b215a99df58c2fa1119dfb888ac8d610" $new = "50bb3102ccdfc2a9e38b4e3cb0d5768f30e9b17f" # 1. 获取变更文件列表并存入临时文件 git diff --name-only --diff-filter=d $old $new > filelist.txt # 2. 使用 --format=zip 配合 Get-Content 读取列表进行打包 # 注意:git archive 本身不支持 --files-from,但我们可以用下面的方式: git archive $new --format=zip -o export.zip $(Get-Content filelist.txt) # 3. 清理临时文件 Remove-Item filelist.txt