[Windows批处理]比对Git两个分支之间的差异,把有改动的文件复制到指定目录
保存为git-diff-copy.bat
@echo off
REM [Windows批处理]比对Git两个分支之间的差异,把有改动的文件复制到指定目录
setlocal enabledelayedexpansion
REM 1:设置被复制的git项目文件夹(尾部要加"\")
set copy_from=..\vue-vben-admin\
REM 2:设置复制的目标文件夹
set copy_to=%~dp0
REM 设置要比对的两个分支名称
set git_from=v2
set git_to=HEAD
set git_to=--cached
REM 读取 diff.txt 中的文件路径并逐个复制到当前文件夹
for /f "delims=" %%i in ('git --git-dir %copy_from%.git diff --name-only %git_from% %git_to%') do (
REM 获取要复制的文件路径
set "filepath=%%i"
set "filepath=!filepath:/=\!"
REM 文件夹自动创建
for %%F in ("%copy_to%\!filepath!") do set "folderpath=%%~dpF"
if not exist "!folderpath!" (
mkdir "!folderpath!"
)
REM 复制文件到当前文件夹
echo copy To "%copy_to%!filepath!"
copy "%copy_from%!filepath!" "%copy_to%!filepath!" 1>nul
)
echo All files copied.
pause
本文来自博客园,作者:项希盛,转载请注明原文链接:https://www.cnblogs.com/xiangxisheng/p/18362614