-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitupd.bat
62 lines (39 loc) · 1.3 KB
/
gitupd.bat
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
@echo off
cd C:\gitsync
:: 添加所有更改
git add .
:: 提交更改
git commit -m "Auto commit."
:: 获取当前时间并格式化为分支名称(如:backup_YYYYMMDD_HHMMSS)
for /f "tokens=1-4 delims=:. " %%i in ("%date% %time%") do (
set datetime=%%i%%j%%k_%%l
)
set branchname=backup_%datetime%
:: 拉取最新的更改
git pull origin master
:: 检查是否有合并冲突并使用 'ours' 策略无条件合并
if %errorlevel% neq 0 (
echo Pull failed due to conflicts. Creating backup branch and attempting to merge using 'ours' strategy.
:: 从远程创建新的备份分支
git fetch origin
git branch %branchname% origin/master
git push origin %branchname%
:: 进行合并,选择本地分支的更改
git merge -X ours origin/master
if %errorlevel% neq 0 (
echo Merge using 'ours' strategy failed. Please check manually.
exit /b %errorlevel%
)
)
:: 推送到 origin 仓库的 master 分支
git push origin master
:: 合并 origin/master 到本地 master 使用 'ours' 策略
git fetch origin
git merge -X ours origin/master
:: 检查合并结果
if %errorlevel% neq 0 (
echo Merge using 'ours' strategy failed. Please check manually.
exit /b %errorlevel%
)
echo All operations completed successfully.
exit /b