Files
douyi_guaji_main/auto_commit_push.ps1
T

53 lines
1.7 KiB
PowerShell

# 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 "Auto Commit Script Running: $timestamp" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
try {
# Check for changes
$status = git status --porcelain
if ($status) {
Write-Host "Changes detected, starting commit..." -ForegroundColor Yellow
# Add all modified files
git add -A
# Create commit message with timestamp
$commitMessage = "Auto commit: $timestamp - Hourly auto save"
git commit -m $commitMessage
Write-Host "Commit successful: $commitMessage" -ForegroundColor Green
# Push to GitHub
Write-Host "Pushing to GitHub..." -ForegroundColor Yellow
git push origin main
Write-Host "Push successful!" -ForegroundColor Green
} else {
Write-Host "No changes detected, skipping commit." -ForegroundColor Gray
}
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Script execution completed" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
} catch {
Write-Host "Error: $_" -ForegroundColor Red
Write-Host "Stack trace: $($_.ScriptStackTrace)" -ForegroundColor Red
exit 1
}