基于git的增量部署工具

版权声明:本文为博主原创文章,转载请注明出处 https://blog.csdn.net/attwice/article/details/79747010

该批处理文件适用场景: windows+git

@echo off
setlocal enabledelayedexpansion
rem 提取增量发布的源码文件(基于git的项目)到指定目录(dest_dir)
rem 调用格式:incdeploy.bat [param1, [param2]]
rem 0个参数:git diff --name-only
rem 1个参数:git diff --name-only param1
rem 2个参数:git diff --name-only param1 param2

rem if "%2"=="" goto :need_two_params
rem if "%1"=="" goto :need_two_params

rem 设置增量备份主目录
set "dest_dir=D:\xxx\xxx"
rem 参数定义
set "src_dir=%cd%"
set "file_name=update-%date:~0,4%%date:~5,2%%date:~8,2%"
set "upd_dir=%dest_dir%\%file_name%"
set "diff_file=%upd_dir%.txt"

rem 如果存在增量备份目录,先删除再新建
if exist %upd_dir% rd /s /q %upd_dir%
mkdir %upd_dir%
rem 用【git diff】命令获取2个版本之间改动的文件
git diff --name-only %1 %2 > %diff_file%
if not %errorlevel% == 0 (
  echo 运行【git diff】出错,检查【commit id】是否正确!
  goto exit
)

rem 利用【xcopy】拷贝文件
for /f "delims=" %%i in (%diff_file%) do (
  set ia=%%i
  set ib=!ia:/=\!
  echo F | xcopy %src_dir%\!ib! %upd_dir%\!ib! /S /Q /Y
)
goto end

:need_two_params
echo 需要输入1个或2个参数:【commit id】
goto exit

:exit
echo.
echo 程序运行【失败】
exit /b 1

:end
echo.
tree /F %upd_dir%
echo 程序运行【成功】
exit /b 0
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页