Tips:文件名第一个为目标分支,后面逗号的几个分支都是需要合并到该目标分支的远程分支。
@echo off
set nowPath=%~n0
::~~~~~~~~~~~~~~~~~~~~~~为了切换分支,必须对当前分支做拉取提交动作 本地分支localPath~~~~~~~~~~~
for /f "delims=" %%i in ('git branch^| find "*"') do set localPath=%%i
echo "拉取%localPath:~2%分支"
git pull origin %localPath:~2%
if "%errorlevel%"=="1" (
echo 分支合并有冲突,请手动合并 从%localPath:~2%拉取%localPath:~2%
pause
exit
)
echo "拉取完毕"
echo "添加未列入版本管理的文件"
git add .
git rm --cached *.bat
echo "提交并且注释添加"
git commit -am "%date% %time%"
echo "提交%localPath:~2%至远程分支"
git push origin %localPath:~2%:%localPath:~2%
::~~~~~~~~~~~~~~~~~~~~~~~~~~切换到目的分支,文件名第一个分支为总分支,总分支拉取#分隔的后面几个分支~~~~~~~~~~~~~~~~~~~~
echo ~~~~~~~~~~~~~~~~~~~~~本地分支处理完毕,切换远程分支处理~~~~~~~~~~~~~~~~~~~~~
echo 切换到第一个目标分支
for /f "delims=," %%i in ("%nowPath%") do set targetPath=%%i
echo 切换到%targetPath%分支
git checkout %targetPath%
for %%a in (%nowPath%) do (
echo ~~~~~~~~~~~~~~~~~~~~~~~~拉取%%a分支~~~~~~~~~~~~~~~~~~~~~~
git pull origin %%a
if "%errorlevel%"=="1" (
echo 分支合并有冲突,请手动合并 从%targetPath%拉取%%a
pause
exit
)
)
echo ~~~~~~~~~~~~从目标分支%targetPath%提交到远程~~~~~~~~~~~~~~~~~~~
git push origin %targetPath%
echo ~~~~~~~~~~~~切换到原来的分支%localPath:~2%~~~~~~~~~~~~~~~~~~~
git checkout %localPath:~2%
echo 切换完成
pause