通过批处理批量更新代码(git pull)
·
在微服务架构模式下,当服务数量过多,且每一个服务都有独立的git仓库地址时,如果你想把所有的服务拉到本地或者更新本地所有服务时,会有一个困境,上百个服务需要手动一个一个去更新,妥妥的体力活。所以写了下面这个脚本,批量更新,减少体力活。
- 遍历当前路径的所有文件夹
@echo off
rem 启用变量延迟功能
setlocal enabledelayedexpansion
for /d %%x in (*) do (
set gitpath=%cd%\%%x\.git
rem for命令中临时变量的用法
rem echo !gitpath!
if not exist !gitpath! (
echo !gitpath! file not exist, not exec git pull command
) else (
rem echo !gitpath! file is exist, exec git pull command
cd %cd%\%%x
echo !cd!
git.exe pull --progress -v --no-rebase "origin"
)
)
echo "exec finish"
pause
- 遍历当前路径的下一级目录的所有文件夹
@echo off
rem 启用变量延迟功能
setlocal enabledelayedexpansion
rem 获取当前目录
set currentDir=%cd%
for /d %%x in (*) do (
cd /d %currentDir%\%%x
for /d %%y in (*) do (
set gitpath=%currentDir%\%%x\%%y\.git
rem for命令中临时变量的用法: !gitpath!
if not exist !gitpath! (
echo !gitpath! file not exist, not exec git pull command
) else (
cd %currentDir%\%%x\%%y
echo !cd!
git.exe pull --progress -v --no-rebase "origin"
)
)
rem cd /d %currentDir%
)
echo "exec finish"
pause
PS:关键不在于这个脚本的内容,而是在于通过工具或脚本去解放双手,提高效率的思维。
更多推荐
所有评论(0)