赞
踩
:: gitpullall.bat
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SET MYGIT="D:\Program Files\Git\bin\git.exe"
SET MYHG="D:\Program Files\TortoiseHg\hg.exe"
FOR /D %%X IN (*) DO (
IF EXIST "%%X\.git\" (
CD /D "%%X"
ECHO ===== git pull %%X
%MYGIT% pull --recurse-submodules=yes --ff-only --all --progress
CD /D ..
) ELSE IF EXIST "%%X\.hg\" (
CD /D "%%X"
ECHO ===== hg pull %%X
%MYGIT% pull -u
CD /D ..
) ELSE ECHO ..... Skipped %%X
)
:bye
PAUSE
ENDLOCAL
如果只需要fetch所有remote源,运行gitfetchall.bat批处理文件:
:: gitfetchall.bat
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SET MYGIT="D:\Program Files\Git\bin\git.exe"
FOR /D %%X IN (*) DO (
IF EXIST "%%X\.git\" (
CD /D "%%X"
ECHO ===== git fetching %%X
%MYGIT% fetch --all --recurse-submodules=yes -v --progress
CD /D ..
) ELSE ECHO ..... Skipped %%X
)
:bye
PAUSE
ENDLOCAL
# 打包一个或多个Git库
:: packdir.bat
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SET MY7Z="D:\Program Files\7-Zip\7z.exe"
IF "%1" == "" (
FOR /D %%X IN (*) DO (
IF EXIST "%%X\.git\" (
DEL "%%X.7z" 1>NUL 2>&1
ECHO ===== Packing %%X\.git\ to %%X.7z
%MY7Z% a -mx9 "%%X.7z" "%%X\.git\" 1>NUL
) ELSE ECHO ..... Skipped %%X
)
) ELSE (
DEL "%1.7z" 1>NUL 2>&1
IF EXIST "%1\.git\" (
ECHO ===== Packing %1\.git\ to %1.7z
%MY7Z% a -mx9 "%1.7z" "%1\.git\" 1>NUL
) ELSE FOR /D %%X IN (*) DO (
IF EXIST "%%X\.git\" (
ECHO ===== Packing %%X\.git\ to %1.7z
%MY7Z% a -mx9 "%1.7z" "%%X\.git\" 1>NUL
) ELSE ECHO ..... Skipped %%X
)
)
:bye
PAUSE
ENDLOCAL
在D:\git目录下带参数project运行packdir.bat批处理文件,则仅将project\.git\目录打包为project.7z。
如果参数不是一个子目录名,则将所有子项目的.git\目录打为一个整包,包名为“参数.7z”。
如果不带参数,则对当前目录下所有项目的.git\目录分别打包,包名为对应“子目录名.7z”,包内保存路径"子目录名\.git\"。将打包文件解压后进入.git\上级项目目录,运行"git checkout -f --"即可恢复该项目代码。
如果需要批量恢复所有子项目目录下的代码,运行gitcheckoutall.bat批处理文件:
:: gitcheckoutall.bat
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SET MYGIT="D:\Program Files\Git\bin\git.exe"
FOR /D %%X IN (*) DO (
IF EXIST "%%X\.git\" (
CD /D "%%X"
ECHO ===== git checkout %%X
%MYGIT% checkout --recurse-submodules -f --
CD /D ..
) ELSE ECHO ..... Skipped %%X
)
:bye
PAUSE
ENDLOCALSETLOCAL ENABLEEXTENSIONS
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。