-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-commit.bat
More file actions
74 lines (64 loc) · 1.36 KB
/
git-commit.bat
File metadata and controls
74 lines (64 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
echo ========================================
echo Git 提交脚本
echo ========================================
:: 检查是否在Git仓库中
git status >nul 2>&1
if errorlevel 1 (
echo 错误:当前目录不是Git仓库!
pause
exit /b 1
)
:: 获取commit消息参数
set "commit_msg=%*"
if "%commit_msg%"=="" (
set "commit_msg=update"
)
echo.
echo 正在执行Git操作...
echo 提交消息: %commit_msg%
echo.
:: 执行git add .
echo [1/4] 添加所有文件到暂存区...
git add .
if errorlevel 1 (
echo 错误:git add 失败!
pause
exit /b 1
)
:: 检查是否有文件被修改
git diff --cached --quiet
if errorlevel 1 (
echo [2/4] 文件已添加到暂存区
) else (
echo [2/4] 没有文件需要提交
echo 操作完成!
pause
exit /b 0
)
:: 执行git commit
echo [3/4] 提交更改...
git commit -m "%commit_msg%"
if errorlevel 1 (
echo 错误:git commit 失败!
pause
exit /b 1
)
:: 执行git push
echo [4/4] 推送到远程仓库...
git push
if errorlevel 1 (
echo 错误:git push 失败!
pause
exit /b 1
)
echo.
echo ========================================
echo 操作完成!
echo ========================================
echo 提交消息: %commit_msg%
echo 时间: %date% %time%
echo.
pause