@echo off setlocal cd /d "%~dp0" title 备份代码到 git.yihuiyong.cn echo ============================================ echo 一键备份:本机 + git.yihuiyong.cn echo ============================================ echo. rem ---- 这台电脑的 git 没进系统 PATH,按已知位置找 ---- rem 注意 2026-10-06 改过顺序:优先用系统 Git。 rem 便携版 PortableGit 缺 git-remote-https,一 push 就报 rem "'remote-https' is not a git command" —— 只能提交、传不上服务器, rem 备份看着成功,服务器上其实一直是旧的,比不备份还危险。 set "GIT=" if exist "%ProgramFiles%\Git\cmd\git.exe" set "GIT=%ProgramFiles%\Git\cmd\git.exe" if not defined GIT for /d %%d in ("%USERPROFILE%\.workbuddy\binaries\PortableGit\versions\*") do if exist "%%d\cmd\git.exe" set "GIT=%%d\cmd\git.exe" if not defined GIT set "GIT=git" "%GIT%" --version >nul 2>&1 if errorlevel 1 ( echo [错误] 没有找到 git,无法备份。请把这一屏截图发给我。 goto :END_FAIL ) echo [1/3] 提交前体检(防止坏文件被提交)... set "PY=%USERPROFILE%\.workbuddy\binaries\python\envs\default\Scripts\python.exe" if not exist "%PY%" set "PY=python" if exist "%~dp0CostReview\app\tools\health_check.py" ( "%PY%" "%~dp0CostReview\app\tools\health_check.py" if errorlevel 1 ( echo. echo [中止] 体检没有通过,本次什么都没有提交。 echo 请把上面标[坏]的文件修好,再重新备份。 echo (这一步是保险:坏文件一旦被自动提交,会把服务器上 echo 最后一份好版本也顶掉,备份就变成销毁了。) goto :END_FAIL ) ) else ( echo 没有找到体检脚本,跳过体检。 ) echo 体检通过。 echo. echo [2/3] 把今天的改动存到本机 ... "%GIT%" add -A "%GIT%" diff --cached --quiet if not errorlevel 1 ( echo 没有检测到新改动,跳过这一步。 goto :PUSH ) "%GIT%" commit -m "备份 %DATE% %TIME%" >nul if errorlevel 1 ( echo [错误] 存到本机时出错。请把这一屏截图发给我。 goto :END_FAIL ) echo 完成。 :PUSH echo [3/3] 上传到服务器 ... "%GIT%" push origin main if errorlevel 1 ( echo. echo [错误] 上传失败。可能的原因: echo 1. 需要输入账号和密码,密码处请粘贴访问令牌 echo 2. 别人先推了新内容,需要先合并 echo 3. git 是便携版缺 remote-https,换系统 Git 再试 echo 请把这一屏截图发给我。 goto :END_FAIL ) echo. echo ============================================ echo 备份完成!代码现在有两份: echo 1. 本机 本文件夹里的 .git echo 2. 服务器 git.yihuiyong.cn echo ============================================ echo. pause exit /b 0 :END_FAIL echo. pause exit /b 1