赞
踩
将cloneList.txt和git_clone_batch.bat两个文件,放到用于存放项目的根目录。
在cloneList.txt文件中维护需要批量克隆的http地址,每行一个项目地址。注释用#开头。
双击执行git_clone_batch.bat,则会进行批量克隆项目,若项目已存在,命令会提示已存在该项目,会继续执行下一条命令。
cloneList.txt文件内容示例如下
# 若不指定分支,则下载该项目的默认分支
"git项目的http地址"
# 下载指定分支的代码
#-b "分支名" "git项目的http地址"
git项目的http地址如下
git_clone_batch.bat脚本内容如下
::for loop test
chcp 65001
@echo off
for /f delims^=^ eol^=^# %%c in (cloneList.txt) do git clone %%c
pause
将git_pull_batch.bat文件,放到用于存在项目的根目录,双击执行,则会对该目录下所有项目执行git pull 操作。
PS:使用前应先确认项目是否有未提交的代码,避免存在冲突的情况。
@echo off chcp 65001 for /d %%i in (*) do ( if not %%i==[Filter] ( if exist "%~dp0%%i\.svn\" ( echo 正在更新svn项目 %%i @cd %cd%\%%i && @svn update ) else if exist "%~dp0%%i\.git\" ( echo 正在更新git项目 %%i @cd %cd%\%%i && @git pull ) else ( echo. echo -- 进入文件夹 %%i cd "%~dp0%%i\ for /d %%j in (*) do ( if not %%j==[Filter] ( if exist "%~dp0%%i\%%j\.svn\" ( echo 正在更新svn项目 %%j @cd %~dp0%%i\%%j && @svn update ) else if exist "%~dp0%%i\%%j\.git\" ( echo 正在更新git项目 %%j @cd %~dp0%%i\%%j && @git pull ) ) ) ) ) ) pause
1、将switchList.txt和batch_switch.bat两个文件,放到用于存放项目的根目录。
2、在switchList.txt文件中维护相关数据,每行的文本内容为项目+目标分支,以空格为间隔。
3、双击执行batch_switch.bat,则会切换存在于switchList.txt文件中的项目的分支,根目录中若不存在其文件中的描述的项目名,则会跳过处理。
batch_switch.bat文件的内容如下
@echo off chcp 65001 for /f delims^=^ eol^=^# %%c in (switchList.txt) do ( for /f "tokens=1,2" %%a in ("%%c") do ( set d=%%a&set t=%%b if exist %%a (echo 项目:%%a 分支将准备切换至 %%b cd %%a git fetch git checkout %%b git pull cd ../ ) ) ) pause
switchList.txt文件的内容格式如下
"项目名" "目标分支"
"项目名" "目标分支"
switchList.txt文件内容示例如下
ProJect1 branch1
Project2 branch2
PS:
1. 若项目根目录中存在改文件中的项目名,则会切换对应的分支名,不存在,则跳过。
2. 分支名要在其项目中存在,不存在的话,则没办法切换。
用途: 当版本迭代时,如从X10至X11版本时,需要切换项目的分支,可通过该工具,批量快速切换。
这几个脚本的实质还是通过bat脚本批量执行git的命令语句。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。