Files
recommend/git_push.bat
赵杰 Jie Zhao (雄狮汽车科技) 7ab87e8f15 优化注册功能
2025-11-03 12:29:32 +08:00

87 lines
2.1 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
REM -*- coding: utf-8 -*-
REM Git 自动上传脚本Windows
chcp 65001 >nul
setlocal enabledelayedexpansion
echo === Git 自动上传脚本 ===
REM 检查是否在 git 仓库中
if not exist .git (
echo 错误: 当前目录不是 git 仓库
exit /b 1
)
REM 获取当前分支
for /f "tokens=2" %%i in ('git branch --show-current 2^>nul') do set CURRENT_BRANCH=%%i
if "!CURRENT_BRANCH!"=="" (
for /f "delims=" %%i in ('git rev-parse --abbrev-ref HEAD 2^>nul') do set CURRENT_BRANCH=%%i
)
echo 当前分支: !CURRENT_BRANCH!
REM 检查是否有未提交的更改
git status --porcelain >nul 2>&1
if errorlevel 1 (
echo 没有需要提交的更改
set /p CONTINUE="是否继续检查远程更新? (y/n) "
if /i "!CONTINUE!"=="y" (
echo 拉取远程更新...
git pull origin !CURRENT_BRANCH! 2>nul || echo 拉取失败,可能没有远程分支
)
exit /b 0
)
REM 显示当前状态
echo 当前更改状态:
git status --short
REM 询问是否继续
set /p CONTINUE="是否继续提交并推送? (y/n) "
if /i not "!CONTINUE!"=="y" (
echo 操作已取消
exit /b 0
)
REM 获取提交信息
if "%1"=="" (
set /p COMMIT_MSG="请输入提交信息(或直接按回车使用默认信息): "
if "!COMMIT_MSG!"=="" (
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set DATE_STR=%%a-%%b-%%c
for /f "tokens=1-2 delims=: " %%a in ('time /t') do set TIME_STR=%%a:%%b
set COMMIT_MSG=chore: update code !DATE_STR! !TIME_STR!
)
) else (
set COMMIT_MSG=%1
)
REM 添加所有更改
echo 添加文件到暂存区...
git add -A
if errorlevel 1 (
echo 添加文件失败
exit /b 1
)
REM 提交更改
echo 提交更改...
git commit -m "!COMMIT_MSG!"
if errorlevel 1 (
echo 提交失败
exit /b 1
)
echo 提交成功!
REM 推送到远程
echo 推送到远程仓库...
git push origin !CURRENT_BRANCH!
if errorlevel 1 (
echo 推送失败,可能需要设置远程仓库或认证
echo 提示: 可以手动执行 'git push origin !CURRENT_BRANCH!'
exit /b 1
)
echo ✓ 推送成功!
echo === 完成 ===