快速提交GIT

新建任意名字的.cmd文件,添加内容如下:

@echo off  
setlocal  
  
:: 切换到你的Git仓库目录(如果脚本不在仓库根目录下)  
:: cd /d C:\path\to\your\repo  
  
:: 检查当前目录是否为Git仓库
if not exist .git (
    echo This is not a Git repository.
    goto end
)

::从远程仓库获取最新的更改
git pull origin master

:: 获取当前时间,并格式化为YYYY-MM-DD HH:MM:SS的格式
for /f "tokens=2 delims==" %%I in ('wmic OS Get localdatetime /value') do set datetime=%%I

:: 转换datetime格式为YYYY-MM-DD HH:MM
set year=%datetime:~0,4%
set month=%datetime:~4,2%
set day=%datetime:~6,2%
set hour=%datetime:~8,2%
set minute=%datetime:~10,2%
set formatted_datetime=%year%-%month%-%day% %hour%:%minute%

:: 输出格式化后的日期和时间
echo Committing changes with message: %formatted_datetime%

:: 添加所有已修改的文件到暂存区
echo Adding all modified files to staging area...
git add .

:: 提交更改,使用当前时间作为提交描述
git commit -m "Automated commit at %formatted_datetime%"

:: 如果需要,可以在这里添加推送更改到远程仓库的命令

git push -f origin master

:: 脚本结束
:end
echo Script execution completed.
endlocal