From 08a0b41834fcce7c61f8fd64d12ae48ff7b78a22 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 21 Dec 2025 22:46:00 +0800 Subject: [PATCH] Auto commit: 2025-12-21 22:45:59 - Hourly auto save --- ...2025-12-21_14-42Z-每小时-git-提交和推送.md | 733 ++++++++++++++++++ ...¿�存一次我的修改,并提交和推送我的代码到github.md | 38 - setup_auto_commit.ps1 | 103 +++ 设置定时任务说明.md | 19 +- 4 files changed, 854 insertions(+), 39 deletions(-) create mode 100644 .specstory/history/2025-12-21_14-42Z-每小时-git-提交和推送.md delete mode 100644 .specstory/history/2025-12-21_14-42Z-让git每一小时保存一次我的修改,并提交和推送我的代码到github.md create mode 100644 setup_auto_commit.ps1 diff --git a/.specstory/history/2025-12-21_14-42Z-每小时-git-提交和推送.md b/.specstory/history/2025-12-21_14-42Z-每小时-git-提交和推送.md new file mode 100644 index 0000000..a40e2ca --- /dev/null +++ b/.specstory/history/2025-12-21_14-42Z-每小时-git-提交和推送.md @@ -0,0 +1,733 @@ + + + + +# 每小时 git 提交和推送 (2025-12-21 14:42Z) + +_**User (2025-12-21 14:42Z)**_ + +让git每一小时保存一次我的修改,并提交和推送我的代码到github + +--- + +_**Agent (model default, mode Agent)**_ + + + +--- + + + +--- + +_**User (2025-12-21 14:44Z)**_ + +让git每一小时保存一次我的修改,并提交和推送我的代码到github + +--- + +_**Agent (model default, mode Agent)**_ + + + +--- + + +检查项目结构,准备创建自动提交和推送脚本。 + + +--- + + +
+ Tool use: **list_dir** • Listed directory, 0 results + +No results found +
+
+ +--- + + +
+Tool use: **glob_file_search** • Searched codebase ".git*" • **1** result in **1** directory + +Directory: **c:\Users\12742\Desktop\douyin_guaji-main** (1 file) + +| File | +|------| +| `.gitignore` | + +
+
+ +--- + + + +--- + + +检查 Git 仓库状态,然后创建自动提交和推送脚本。 + + +--- + + +
Tool use: **run_terminal_cmd** • Run command: cd "C:\Users\12742\Desktop\douyin_guaji-main" && git status + +```bash +cd "C:\Users\12742\Desktop\douyin_guaji-main" && git status +``` + +``` +����λ�� C:\Users\12742\AppData\Local\Temp\ps-script-9474d138-3383-433e-b54b-92cc58a075b6.ps1:7 �ַ�: 47 ++ cd "C:\Users\12742\Desktop\douyin_guaji-main" && git status ++ ~~ +��ǡ�&&�����Ǵ˰汾�е���Ч���ָ����� + + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + + FullyQualifiedErrorId : InvalidEndOfLine + + +``` +
+
+ +--- + + + +--- + + + + + +--- + + +
Tool use: **run_terminal_cmd** • Run command: cd "C:\Users\12742\Desktop\douyin_guaji-main"; git status + +```bash +cd "C:\Users\12742\Desktop\douyin_guaji-main"; git status +``` + +``` +On branch main +Your branch is up to date with 'origin/main'. + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git restore <file>..." to discard changes in working directory) + modified: .specstory/.what-is-this.md + modified: ".specstory/history/2025-12-21_13-46Z-\346\240\270\345\277\203\346\214\207\344\273\244.md" + modified: DEPENDENCY_FIXES_REPORT.md + modified: DEPENDENCY_GUIDE.md + modified: FIXES_REPORT.md + modified: check_dependencies.py + modified: config.json + modified: douyin_fudai_flow.py + modified: douyin_logging.py + modified: douyin_pixel.py + modified: install_dependencies.py + modified: path_config.py + modified: requirements-minimal.txt + modified: requirements.txt + modified: tools/webgui_smoketest.py + modified: web_gui.py + +Untracked files: + (use "git add <file>..." to include in what will be committed) + ".specstory/history/2025-12-21_14-42Z-\350\256\251git\346\257\217\344\270\200\345\260\217\346\227\266\344\277\235\345\255\230\344\270\200\346\254\241\346\210\221\347\232\204\344\277\256\346\224\271,\345\271\266\346\217\220\344\272\244\345\222\214\346\216\250\351\200\201\346\210\221\347\232\204\344\273\243\347\240\201\345\210\260github.md" + +no changes added to commit (use "git add" and/or "git commit -a") + +``` +
+
+ +--- + + + +--- + + +创建自动提交和推送脚本,并编写设置说明。 + + +--- + + + +
Tool use: **write** • Edit file: C:\Users\12742\Desktop\douyin_guaji-main\auto_commit_push.ps1 + +**Chunk 1** +Lines added: 51, lines removed: 1 + +```diff +@@ -1,1 +1,51 @@ +- ++ # Git自动提交和推送脚本 ++ # 每小时自动保存修改、提交并推送到GitHub ++ ++ $ErrorActionPreference = "Stop" ++ ++ # 切换到项目目录 ++ $projectPath = "C:\Users\12742\Desktop\douyin_guaji-main" ++ Set-Location $projectPath ++ ++ # 获取当前时间 ++ $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" ++ ++ Write-Host "========================================" -ForegroundColor Cyan ++ Write-Host "自动提交脚本运行时间: $timestamp" -ForegroundColor Cyan ++ Write-Host "========================================" -ForegroundColor Cyan ++ ++ try { ++ # 检查是否有修改 ++ $status = git status --porcelain ++ ++ if ($status) { ++ Write-Host "检测到文件修改,开始提交..." -ForegroundColor Yellow ++ ++ # 添加所有修改的文件 ++ git add -A ++ ++ # 创建提交信息(包含时间戳) ++ $commitMessage = "自动提交: $timestamp - 每小时自动保存" ++ git commit -m $commitMessage ++ ++ Write-Host "提交成功: $commitMessage" -ForegroundColor Green ++ ++ # 推送到GitHub ++ Write-Host "正在推送到GitHub..." -ForegroundColor Yellow ++ git push origin main ++ ++ Write-Host "推送成功!" -ForegroundColor Green ++ } else { ++ Write-Host "没有检测到文件修改,跳过提交。" -ForegroundColor Gray ++ } ++ ++ Write-Host "========================================" -ForegroundColor Cyan ++ Write-Host "脚本执行完成" -ForegroundColor Cyan ++ Write-Host "========================================" -ForegroundColor Cyan ++ ++ } catch { ++ Write-Host "错误: $_" -ForegroundColor Red ++ Write-Host "堆栈跟踪: $($_.ScriptStackTrace)" -ForegroundColor Red ++ exit 1 ++ } ++ +``` + +
+ +
+ +--- + + + +
Tool use: **write** • Edit file: C:\Users\12742\Desktop\douyin_guaji-main\auto_commit_push.bat + +**Chunk 1** +Lines added: 11, lines removed: 1 + +```diff +@@ -1,1 +1,11 @@ +- ++ @echo off ++ REM Git自动提交和推送批处理脚本 ++ REM 每小时自动保存修改、提交并推送到GitHub ++ ++ cd /d "C:\Users\12742\Desktop\douyin_guaji-main" ++ ++ REM 运行PowerShell脚本 ++ powershell.exe -ExecutionPolicy Bypass -File "%~dp0auto_commit_push.ps1" ++ ++ pause ++ +``` + +
+ +
+ +--- + + + +
Tool use: **write** • Edit file: C:\Users\12742\Desktop\douyin_guaji-main\设置定时任务说明.md + +**Chunk 1** +Lines added: 108, lines removed: 1 + +```diff +@@ -1,1 +1,108 @@ +- ++ # Git自动提交和推送 - 设置说明 ++ ++ 本说明将帮助您设置Windows任务计划程序,使Git每小时自动保存、提交并推送代码到GitHub。 ++ ++ ## 方法一:使用Windows任务计划程序(推荐) ++ ++ ### 步骤1:打开任务计划程序 ++ 1. 按 `Win + R` 键,输入 `taskschd.msc`,然后按回车 ++ 2. 或者:开始菜单 → 搜索"任务计划程序" → 打开 ++ ++ ### 步骤2:创建基本任务 ++ 1. 在右侧操作栏中,点击"创建基本任务" ++ 2. 任务名称:`Git自动提交推送` ++ 3. 描述:`每小时自动保存修改、提交并推送到GitHub` ++ 4. 点击"下一步" ++ ++ ### 步骤3:设置触发器 ++ 1. 选择"每天" ++ 2. 点击"下一步" ++ 3. 开始时间:选择当前时间或任意时间 ++ 4. 重复任务间隔:选择"1小时" ++ 5. 持续时间:选择"无限期"或设置结束日期 ++ 6. 点击"下一步" ++ ++ ### 步骤4:设置操作 ++ 1. 选择"启动程序" ++ 2. 点击"下一步" ++ 3. 程序或脚本:输入 `powershell.exe` ++ 4. 添加参数:输入 `-ExecutionPolicy Bypass -File "C:\Users\12742\Desktop\douyin_guaji-main\auto_commit_push.ps1"` ++ 5. 起始于:输入 `C:\Users\12742\Desktop\douyin_guaji-main` ++ 6. 点击"下一步" ++ ++ ### 步骤5:完成设置 ++ 1. 勾选"当单击完成时,打开此任务属性的对话框" ++ 2. 点击"完成" ++ ++ ### 步骤6:高级设置(重要) ++ 在任务属性对话框中: ++ 1. 切换到"常规"选项卡 ++ - 勾选"不管用户是否登录都要运行" ++ - 勾选"使用最高权限运行" ++ - 配置:选择您的Windows版本(Windows 10/11) ++ ++ 2. 切换到"条件"选项卡 ++ - 取消勾选"只有在计算机使用交流电源时才启动此任务"(如果使用笔记本) ++ ++ 3. 切换到"设置"选项卡 ++ - 如果任务失败,立即启动任务:选择"是" ++ - 如果请求的任务正在运行:选择"并行运行新实例"或"停止现有实例" ++ ++ 4. 点击"确定"保存 ++ ++ ### 步骤7:测试任务 ++ 1. 在任务计划程序中找到刚创建的任务 ++ 2. 右键点击 → 选择"运行" ++ 3. 检查是否成功执行 ++ ++ ## 方法二:使用PowerShell命令快速设置 ++ ++ 您也可以使用以下PowerShell命令(以管理员身份运行)快速创建任务: ++ ++ ```powershell ++ $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -File `"C:\Users\12742\Desktop\douyin_guaji-main\auto_commit_push.ps1`"" -WorkingDirectory "C:\Users\12742\Desktop\douyin_guaji-main" ++ ++ $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Hours 1) -RepetitionDuration (New-TimeSpan -Days 365) ++ ++ $principal = New-ScheduledTaskPrincipal -UserId "$env:USERNAME" -RunLevel Highest ++ ++ $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable ++ ++ Register-ScheduledTask -TaskName "Git自动提交推送" -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Description "每小时自动保存修改、提交并推送到GitHub" ++ ``` ++ ++ ## 注意事项 ++ ++ 1. **Git凭据**:首次推送可能需要输入GitHub用户名和密码(或访问令牌) ++ - 建议使用Personal Access Token (PAT) 而不是密码 ++ - 可以在GitHub设置中生成:Settings → Developer settings → Personal access tokens ++ ++ 2. **网络连接**:确保计算机连接到互联网,否则推送会失败 ++ ++ 3. **Git配置**:确保已配置Git用户信息: ++ ```bash ++ git config --global user.name "您的用户名" ++ git config --global user.email "您的邮箱" ++ ``` ++ ++ 4. **查看日志**:任务计划程序会记录每次执行的日志,可以在任务属性中查看历史记录 ++ ++ 5. **手动测试**:您可以双击 `auto_commit_push.bat` 文件来手动测试脚本是否正常工作 ++ ++ ## 停止自动提交 ++ ++ 如果需要停止自动提交: ++ 1. 打开任务计划程序 ++ 2. 找到"Git自动提交推送"任务 ++ 3. 右键点击 → 选择"禁用"或"删除" ++ ++ ## 修改提交频率 ++ ++ 如果需要修改提交频率(例如每30分钟或每2小时): ++ 1. 打开任务计划程序 ++ 2. 找到"Git自动提交推送"任务 ++ 3. 右键点击 → 选择"属性" ++ 4. 切换到"触发器"选项卡 ++ 5. 编辑触发器,修改重复间隔 ++ 6. 保存更改 ++ +``` + +
+ +
+ +--- + + + +--- + + +测试脚本是否正常工作: + + +--- + + +
Tool use: **run_terminal_cmd** • Run command: cd "C:\Users\12742\Desktop\douyin_guaji-main"; powershell.exe -ExecutionPolicy Bypass -File "auto_commit_push.ps1" + +```bash +cd "C:\Users\12742\Desktop\douyin_guaji-main"; powershell.exe -ExecutionPolicy Bypass -File "auto_commit_push.ps1" +``` + +``` +����λ�� C:\Users\12742\Desktop\douyin_guaji-main\auto_commit_push.ps1:31 �ַ�: 21 ++ Write-Host "提交成功: $commitMessage" -ForegroundColor Green ++ ~~~~~~~ +����ʽ������а�������ı�ǡ�提交成功:���� + + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + + FullyQualifiedErrorId : UnexpectedToken + + +``` +
+
+ +--- + + + +--- + + +修复脚本中的编码问题: + + +--- + + +
Tool use: **read_file** • Read file: C:\Users\12742\Desktop\douyin_guaji-main\auto_commit_push.ps1 + +
+
+ +--- + + + +--- + + +修复编码问题,更新脚本以兼容中文输出: + + +--- + + + +
Tool use: **search_replace** • Edit file: C:\Users\12742\Desktop\douyin_guaji-main\auto_commit_push.ps1 + +**Chunk 1** +Lines added: 19, lines removed: 18 + +```diff +@@ -1,50 +1,51 @@ +- # Git自动提交和推送脚本 +- # 每小时自动保存修改、提交并推送到GitHub ++ # Git Auto Commit and Push Script ++ # Auto save, commit and push to GitHub every hour + ++ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 + $ErrorActionPreference = "Stop" + +- # 切换到项目目录 ++ # Switch to project directory + $projectPath = "C:\Users\12742\Desktop\douyin_guaji-main" + Set-Location $projectPath + +- # 获取当前时间 ++ # Get current timestamp + $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" + + Write-Host "========================================" -ForegroundColor Cyan +- Write-Host "自动提交脚本运行时间: $timestamp" -ForegroundColor Cyan ++ Write-Host "Auto Commit Script Running: $timestamp" -ForegroundColor Cyan + Write-Host "========================================" -ForegroundColor Cyan + + try { +- # 检查是否有修改 ++ # Check for changes + $status = git status --porcelain + + if ($status) { +- Write-Host "检测到文件修改,开始提交..." -ForegroundColor Yellow ++ Write-Host "Changes detected, starting commit..." -ForegroundColor Yellow + +- # 添加所有修改的文件 ++ # Add all modified files + git add -A + +- # 创建提交信息(包含时间戳) +- $commitMessage = "自动提交: $timestamp - 每小时自动保存" ++ # Create commit message with timestamp ++ $commitMessage = "Auto commit: $timestamp - Hourly auto save" + git commit -m $commitMessage + +- Write-Host "提交成功: $commitMessage" -ForegroundColor Green ++ Write-Host "Commit successful: $commitMessage" -ForegroundColor Green + +- # 推送到GitHub +- Write-Host "正在推送到GitHub..." -ForegroundColor Yellow ++ # Push to GitHub ++ Write-Host "Pushing to GitHub..." -ForegroundColor Yellow + git push origin main + +- Write-Host "推送成功!" -ForegroundColor Green ++ Write-Host "Push successful!" -ForegroundColor Green + } else { +- Write-Host "没有检测到文件修改,跳过提交。" -ForegroundColor Gray ++ Write-Host "No changes detected, skipping commit." -ForegroundColor Gray + } + + Write-Host "========================================" -ForegroundColor Cyan +- Write-Host "脚本执行完成" -ForegroundColor Cyan ++ Write-Host "Script execution completed" -ForegroundColor Cyan + Write-Host "========================================" -ForegroundColor Cyan + + } catch { +- Write-Host "错误: $_" -ForegroundColor Red +- Write-Host "堆栈跟踪: $($_.ScriptStackTrace)" -ForegroundColor Red ++ Write-Host "Error: $_" -ForegroundColor Red ++ Write-Host "Stack trace: $($_.ScriptStackTrace)" -ForegroundColor Red + exit 1 + } +``` + +
+ +
+ +--- + + + +--- + + +再次测试脚本: + + +--- + + +
Tool use: **run_terminal_cmd** • Run command: cd "C:\Users\12742\Desktop\douyin_guaji-main"; powershell.exe -ExecutionPolicy Bypass -File "auto_commit_push.ps1" + +```bash +cd "C:\Users\12742\Desktop\douyin_guaji-main"; powershell.exe -ExecutionPolicy Bypass -File "auto_commit_push.ps1" +``` + +``` +======================================== +Auto Commit Script Running: 2025-12-21 22:45:00 +======================================== +Changes detected, starting commit... +warning: in the working copy of 'config.json', LF will be replaced by CRLF the next time Git touches it +warning: in the working copy of 'douyin_fudai_flow.py', LF will be replaced by CRLF the next time Git touches it +warning: in the working copy of 'douyin_logging.py', LF will be replaced by CRLF the next time Git touches it +warning: in the working copy of 'douyin_pixel.py', LF will be replaced by CRLF the next time Git touches it +warning: in the working copy of 'path_config.py', LF will be replaced by CRLF the next time Git touches it +warning: in the working copy of 'tools/webgui_smoketest.py', LF will be replaced by CRLF the next time Git touches it +warning: in the working copy of 'web_gui.py', LF will be replaced by CRLF the next time Git touches it +[main 5b8dd6e] Auto commit: 2025-12-21 22:45:00 - Hourly auto save + 17 files changed, 1921 insertions(+), 88 deletions(-) + create mode 100644 ".specstory/history/2025-12-21_14-42Z-\350\256\251git\346\257\217\344\270\200\345\260\217\346\227\266\344\277\235\345\255\230\344\270\200\346\254\241\346\210\221\347\232\204\344\277\256\346\224\271,\345\271\266\346\217\220\344\272\244\345\222\214\346\216\250\351\200\201\346\210\221\347\232\204\344\273\243\347\240\201\345\210\260github.md" + create mode 100644 auto_commit_push.bat + create mode 100644 auto_commit_push.ps1 + create mode 100644 "\350\256\276\347\275\256\345\256\232\346\227\266\344\273\273\345\212\241\350\257\264\346\230\216.md" +Commit successful: Auto commit: 2025-12-21 22:45:00 - Hourly auto save +Pushing to GitHub... +To https://github.com/Zzzil/douyin_guaji-main.git + 1a63852..5b8dd6e main -> main +Push successful! +======================================== +Script execution completed +======================================== + +``` +
+
+ +--- + + + +--- + + +脚本已成功运行并推送代码。创建快速设置脚本,用于自动配置 Windows 任务计划程序: + + +--- + + + +
Tool use: **write** • Edit file: C:\Users\12742\Desktop\douyin_guaji-main\setup_auto_commit.ps1 + +**Chunk 1** +Lines added: 103, lines removed: 1 + +```diff +@@ -1,1 +1,103 @@ +- ++ # Setup Auto Commit Task Script ++ # This script will create a Windows scheduled task to run git auto commit every hour ++ ++ # Check if running as administrator ++ $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) ++ ++ if (-not $isAdmin) { ++ Write-Host "This script requires administrator privileges." -ForegroundColor Red ++ Write-Host "Please run PowerShell as Administrator and try again." -ForegroundColor Yellow ++ Write-Host "" ++ Write-Host "Right-click PowerShell -> Run as Administrator" -ForegroundColor Yellow ++ pause ++ exit 1 ++ } ++ ++ $taskName = "Git自动提交推送" ++ $scriptPath = "C:\Users\12742\Desktop\douyin_guaji-main\auto_commit_push.ps1" ++ $workingDir = "C:\Users\12742\Desktop\douyin_guaji-main" ++ ++ Write-Host "========================================" -ForegroundColor Cyan ++ Write-Host "Setting up Git Auto Commit Task" -ForegroundColor Cyan ++ Write-Host "========================================" -ForegroundColor Cyan ++ Write-Host "" ++ ++ # Check if task already exists ++ $existingTask = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue ++ ++ if ($existingTask) { ++ Write-Host "Task '$taskName' already exists." -ForegroundColor Yellow ++ $response = Read-Host "Do you want to remove and recreate it? (Y/N)" ++ if ($response -eq "Y" -or $response -eq "y") { ++ Unregister-ScheduledTask -TaskName $taskName -Confirm:$false ++ Write-Host "Old task removed." -ForegroundColor Green ++ } else { ++ Write-Host "Cancelled." -ForegroundColor Yellow ++ exit 0 ++ } ++ } ++ ++ Write-Host "Creating scheduled task..." -ForegroundColor Yellow ++ ++ # Create action ++ $action = New-ScheduledTaskAction ` ++ -Execute "powershell.exe" ` ++ -Argument "-ExecutionPolicy Bypass -File `"$scriptPath`"" ` ++ -WorkingDirectory $workingDir ++ ++ # Create trigger (start now, repeat every hour, duration 365 days) ++ $trigger = New-ScheduledTaskTrigger ` ++ -Once ` ++ -At (Get-Date) ` ++ -RepetitionInterval (New-TimeSpan -Hours 1) ` ++ -RepetitionDuration (New-TimeSpan -Days 365) ++ ++ # Create principal (run with highest privileges) ++ $principal = New-ScheduledTaskPrincipal ` ++ -UserId "$env:USERNAME" ` ++ -RunLevel Highest ++ ++ # Create settings ++ $settings = New-ScheduledTaskSettingsSet ` ++ -AllowStartIfOnBatteries ` ++ -DontStopIfGoingOnBatteries ` ++ -StartWhenAvailable ` ++ -MultipleInstances IgnoreNew ++ ++ # Register the task ++ try { ++ Register-ScheduledTask ` ++ -TaskName $taskName ` ++ -Action $action ` ++ -Trigger $trigger ` ++ -Principal $principal ` ++ -Settings $settings ` ++ -Description "每小时自动保存修改、提交并推送到GitHub" | Out-Null ++ ++ Write-Host "" ++ Write-Host "========================================" -ForegroundColor Green ++ Write-Host "Task created successfully!" -ForegroundColor Green ++ Write-Host "========================================" -ForegroundColor Green ++ Write-Host "" ++ Write-Host "Task Name: $taskName" -ForegroundColor Cyan ++ Write-Host "Schedule: Every 1 hour" -ForegroundColor Cyan ++ Write-Host "Script: $scriptPath" -ForegroundColor Cyan ++ Write-Host "" ++ Write-Host "You can manage this task in Task Scheduler:" -ForegroundColor Yellow ++ Write-Host " Task Scheduler -> Task Scheduler Library -> $taskName" -ForegroundColor Yellow ++ Write-Host "" ++ Write-Host "To test the task, run:" -ForegroundColor Yellow ++ Write-Host " Start-ScheduledTask -TaskName '$taskName'" -ForegroundColor White ++ Write-Host "" ++ Write-Host "Or manually run: .\auto_commit_push.ps1" -ForegroundColor Yellow ++ Write-Host "" ++ ++ } catch { ++ Write-Host "" ++ Write-Host "Error creating task: $_" -ForegroundColor Red ++ Write-Host "Please check the error message above." -ForegroundColor Yellow ++ exit 1 ++ } ++ ++ pause ++ +``` + +
+ +
+ +--- + + + +--- + + +更新说明文档,添加快速设置脚本的使用说明: + + +--- + + +
Tool use: **read_file** • Read file: C:\Users\12742\Desktop\douyin_guaji-main\设置定时任务说明.md + +
+
+ +--- + + + +--- + diff --git a/.specstory/history/2025-12-21_14-42Z-让git每一小时保存一次我的修改,并提交和推送我的代码到github.md b/.specstory/history/2025-12-21_14-42Z-让git每一小时保存一次我的修改,并提交和推送我的代码到github.md deleted file mode 100644 index 220a51d..0000000 --- a/.specstory/history/2025-12-21_14-42Z-让git每一小时保存一次我的修改,并提交和推送我的代码到github.md +++ /dev/null @@ -1,38 +0,0 @@ - - - - -# 让git每一小时保存一次我的修改,并提交和推送我的代码到github (2025-12-21 14:42Z) - -_**User (2025-12-21 14:42Z)**_ - -让git每一小时保存一次我的修改,并提交和推送我的代码到github - ---- - -_**Agent (model default, mode Agent)**_ - - - ---- - - - ---- - -_**User (2025-12-21 14:42Z)**_ - -让git每一小时保存一次我的修改,并提交和推送我的代码到github - ---- - -_**Agent (model default, mode Agent)**_ - - - ---- - - - ---- - diff --git a/setup_auto_commit.ps1 b/setup_auto_commit.ps1 new file mode 100644 index 0000000..efc6c9b --- /dev/null +++ b/setup_auto_commit.ps1 @@ -0,0 +1,103 @@ +# Setup Auto Commit Task Script +# This script will create a Windows scheduled task to run git auto commit every hour + +# Check if running as administrator +$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) + +if (-not $isAdmin) { + Write-Host "This script requires administrator privileges." -ForegroundColor Red + Write-Host "Please run PowerShell as Administrator and try again." -ForegroundColor Yellow + Write-Host "" + Write-Host "Right-click PowerShell -> Run as Administrator" -ForegroundColor Yellow + pause + exit 1 +} + +$taskName = "Git自动提交推送" +$scriptPath = "C:\Users\12742\Desktop\douyin_guaji-main\auto_commit_push.ps1" +$workingDir = "C:\Users\12742\Desktop\douyin_guaji-main" + +Write-Host "========================================" -ForegroundColor Cyan +Write-Host "Setting up Git Auto Commit Task" -ForegroundColor Cyan +Write-Host "========================================" -ForegroundColor Cyan +Write-Host "" + +# Check if task already exists +$existingTask = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue + +if ($existingTask) { + Write-Host "Task '$taskName' already exists." -ForegroundColor Yellow + $response = Read-Host "Do you want to remove and recreate it? (Y/N)" + if ($response -eq "Y" -or $response -eq "y") { + Unregister-ScheduledTask -TaskName $taskName -Confirm:$false + Write-Host "Old task removed." -ForegroundColor Green + } else { + Write-Host "Cancelled." -ForegroundColor Yellow + exit 0 + } +} + +Write-Host "Creating scheduled task..." -ForegroundColor Yellow + +# Create action +$action = New-ScheduledTaskAction ` + -Execute "powershell.exe" ` + -Argument "-ExecutionPolicy Bypass -File `"$scriptPath`"" ` + -WorkingDirectory $workingDir + +# Create trigger (start now, repeat every hour, duration 365 days) +$trigger = New-ScheduledTaskTrigger ` + -Once ` + -At (Get-Date) ` + -RepetitionInterval (New-TimeSpan -Hours 1) ` + -RepetitionDuration (New-TimeSpan -Days 365) + +# Create principal (run with highest privileges) +$principal = New-ScheduledTaskPrincipal ` + -UserId "$env:USERNAME" ` + -RunLevel Highest + +# Create settings +$settings = New-ScheduledTaskSettingsSet ` + -AllowStartIfOnBatteries ` + -DontStopIfGoingOnBatteries ` + -StartWhenAvailable ` + -MultipleInstances IgnoreNew + +# Register the task +try { + Register-ScheduledTask ` + -TaskName $taskName ` + -Action $action ` + -Trigger $trigger ` + -Principal $principal ` + -Settings $settings ` + -Description "每小时自动保存修改、提交并推送到GitHub" | Out-Null + + Write-Host "" + Write-Host "========================================" -ForegroundColor Green + Write-Host "Task created successfully!" -ForegroundColor Green + Write-Host "========================================" -ForegroundColor Green + Write-Host "" + Write-Host "Task Name: $taskName" -ForegroundColor Cyan + Write-Host "Schedule: Every 1 hour" -ForegroundColor Cyan + Write-Host "Script: $scriptPath" -ForegroundColor Cyan + Write-Host "" + Write-Host "You can manage this task in Task Scheduler:" -ForegroundColor Yellow + Write-Host " Task Scheduler -> Task Scheduler Library -> $taskName" -ForegroundColor Yellow + Write-Host "" + Write-Host "To test the task, run:" -ForegroundColor Yellow + Write-Host " Start-ScheduledTask -TaskName '$taskName'" -ForegroundColor White + Write-Host "" + Write-Host "Or manually run: .\auto_commit_push.ps1" -ForegroundColor Yellow + Write-Host "" + +} catch { + Write-Host "" + Write-Host "Error creating task: $_" -ForegroundColor Red + Write-Host "Please check the error message above." -ForegroundColor Yellow + exit 1 +} + +pause + diff --git a/设置定时任务说明.md b/设置定时任务说明.md index abc12e4..558463e 100644 --- a/设置定时任务说明.md +++ b/设置定时任务说明.md @@ -2,7 +2,24 @@ 本说明将帮助您设置Windows任务计划程序,使Git每小时自动保存、提交并推送代码到GitHub。 -## 方法一:使用Windows任务计划程序(推荐) +## 🚀 快速设置(最简单) + +**推荐方法**:使用自动设置脚本 + +1. **以管理员身份运行PowerShell** + - 右键点击"开始"菜单 → 选择"Windows PowerShell (管理员)" 或 "终端 (管理员)" + +2. **运行设置脚本** + ```powershell + cd "C:\Users\12742\Desktop\douyin_guaji-main" + .\setup_auto_commit.ps1 + ``` + +3. **完成!** 脚本会自动创建定时任务,每小时自动提交和推送代码。 + +--- + +## 方法一:使用Windows任务计划程序(手动设置) ### 步骤1:打开任务计划程序 1. 按 `Win + R` 键,输入 `taskschd.msc`,然后按回车