@echo off :: Set UTF-8 encoding chcp 65001 :: Set window title title UPM Package Update Tool :: Set console color color a echo 开始提交到git upm.... echo 提交upm前请确保当前分支所有改动都已经提交! :: Extract version from package.json for /f "tokens=2 delims=:, " %%i in ('findstr "version" Assets\package.json') do ( set version=%%i ) :: Remove quotes set version=%version:"=% echo 从package.json中读取的版本号为:%version% :: Check if tag exists git tag | findstr "%version%" > nul if %errorlevel% equ 0 ( echo 错误:版本号 %version% 对应的tag已存在! pause exit ) set /p Flg=确认提交的版本号%version%,是否开始提交(y/n) -------- : IF "%Flg%" equ "y" ( echo 开始提交,请勿关闭该窗口! :: Delete local upm branch if exists git branch -D upm 2>nul :: Create new upm branch from current Assets folder git subtree split --prefix=Assets --branch upm :: Force update local upm branch with remote changes git fetch origin upm git checkout upm git reset --hard origin/upm :: Create new subtree split git checkout master git subtree split --prefix=Assets --branch upm-temp :: Apply new changes and force push git checkout upm git merge upm-temp --allow-unrelated-histories -X theirs git branch -D upm-temp :: Create and push tag git tag %version% upm git push -f origin upm --tags :: Return to original branch git checkout master GOTO :END ) :END echo 执行完成! pause exit