Bat merge git branch

Bat branch consolidation projects and reduce time consolidation mistakes manually operated. Please note that output information, the script is not automatically handle many cases, require manual processing.
Warehouse addresses, etc. are written target branch dead, you can make some modifications from the console input.

@echo off
::rem 窗口标题
@title 脚本合并

::rem 输出合并路径
echo\&echo  r4.6_mq_hc   r4.6_Time

::rem GIT仓库的根目录
cd /d E:\Git\YLPT-LiXin-Database

::rem 检查工作区是否干净
call:CheckWorkingTree

::rem 合并分支。第一个参数源分支,第二个参数目标分支

call:mergeBranch r4.6_mq_hc    r4.7
call:mergeBranch r4.7          r4.7_mainService



echo\&echo done...
pause
exit



::rem 合并分支
:mergeBranch

git checkout %1
if not %errorlevel%==0  (
echo 切换到%1分支出现问题。新开窗口解决完错误后,继续……
"C:\Program Files\Git\git-bash.exe"
)

git pull 

if not %errorlevel%==0  (
echo 分支%1获取遇到问题。新开窗口解决完错误后,继续……
"C:\Program Files\Git\git-bash.exe"
)

git checkout %2

if not %errorlevel%==0  (
echo 切换到分支%2出现问题。新开窗口解决完错误后,继续……
"C:\Program Files\Git\git-bash.exe"
)


git pull 

if not %errorlevel%==0  (
echo  分支%2获取遇到问题。新开窗口解决完错误后,继续……
"C:\Program Files\Git\git-bash.exe"
)

git merge %1 
set mergeStatus=%errorlevel%
if %mergeStatus%==0  (
git push
echo  ********************** %1 合并到 %2  完成,并提交!!!!!!  **********************
)

if not %mergeStatus%==0  (
echo 合并结果确认,确认以后继续……
"C:\Program Files\Git\git-bash.exe"
)

echo  ********************** %1 合并到 %2  结束!!!!!!  **********************

goto:eof

::rem  检查工作区是否干净
::rem https://stackoverflow.com/questions/5139290/how-to-check-if-theres-nothing-to-be-committed-in-the-current-branch
:CheckWorkingTree

git diff --exit-code
if not %errorlevel%==0  (
echo 合并前保证工作区干净。工作区有未暂存的更改,处理后重新运行
"C:\Program Files\Git\git-bash.exe"
pause
exit
)


git diff --cached --exit-code
if not %errorlevel%==0  (
echo 合并前保证工作区干净。工作区有未commit的文件,处理后重新运行
"C:\Program Files\Git\git-bash.exe"
pause
exit
)


git ls-files --other --exclude-standard --directory 
if not %errorlevel%==0  (
echo 合并前保证工作区干净。工作区有未跟踪的文件,处理后重新运行
"C:\Program Files\Git\git-bash.exe"
pause
exit
)

goto:eof

Guess you like

Origin www.cnblogs.com/-dawn/p/12244054.html