去发现生活中的美好,记录生活中的点点滴滴

批量拉取多个git项目文件(Windows&Linux)

git admin 505℃

Windows:
将以下代码复制到gitpull.txt,然后改后缀gitpull.bat,放到多个git项目根目录执行即可,会根据带有.git项目遍历拉取。

::-------------------------------------
:: @date 2023-05-19
:: @name   find all .git and pull
::-------------------------------------
@echo off
setlocal

@REM normalize the relative path to a shorter absolute path.
pushd "%~dp0"
set repos_path=%CD%
popd

call :find_and_pull %repos_path%
echo. & echo Finished. & pause>nul
goto :EOF

::-------------------------------------
:: @name   find_and_pull
:: @param  %1 base directory to find .git
:: @usage  call :find_and_pull %base_dir%
::-------------------------------------
:find_and_pull
for /d %%i in (%1\*) do (
    cd %%i
    if exist .git (
        echo. & echo [ START git pull FROM ] %%i
        git pull
    ) else (
        call :find_and_pull %%i
    )
)
goto :EOF

Linux:
将以下代码拷贝到gitpull.sh,可以修改指定目录,然后执行sh gitpull.sh即可。

# Title: git pull current file
# Desc: find all .git and pull
# Date: 2023-5-19

echo "service start ..."

for ml in $(ls /home/service/server_code/)
do
  for service in $(ls /home/service/server_code/$ml/)
  do
    echo $service
    service_ml=/home/service/server_code/$ml/$service/
    if [ -d $service_ml ]; then
      cd /home/service/server_code/$ml/$service/
      git pull
    fi
  done
done

echo " all service restart  done."

转载请注明:永盟博客 » 批量拉取多个git项目文件(Windows&Linux)

喜欢 (2)

Warning: count(): Parameter must be an array or an object that implements Countable in E:\www\blog\wp-includes\class-wp-comment-query.php on line 405