Win10任务计划+PowerShell实现自动推送远程仓库
前言
每次写完代码都要推送到Gitee太麻烦了 就写了一个PowerShell脚本代替 但还是避免不了每次推送都要运行一下 Linux上有cron 实现计划任务 Window上也有类似的叫taskschd.msc 我们使用taskschd 来定期运行推送的脚本就可以的
1. AutoPush.sp1
sp1就是PowerShell的扩展名(后面是数字1而不是字母l) 使用VScode加PowerShell插件可以很好的编写测试ps1脚本  就是这个插件 
Function Push-Java {
Set-Location D:\workspaceFolder\CODE_JAVA
$now = Get-Date
$msg = "==> " + $now.ToString('yyyy年MM月dd日 HH:mm:ss') + " 提交 <=="# 提交的消息
Write-Output $msg >> .\gitpush.log
git status >> .\gitpush.log
git add . >> .\gitpush.log
git commit -m $msg >> .\gitpush.log
git push -u gitee master >> .\gitpush.log
}
Push-Java
复制-粘贴-保存为AutoPush.ps1 运行直接终端: ./AutoPush.ps1 就可以了  正常结果大概像这样
2. taskschd.msc
Win + R 打开运行窗口, 输入taskschd.msc然后回车  然后点创建任务  名字和描述都可以随便写,就叫自动推送吧  然后点上面触发器,再点下面新建  就创建一个每天的吧  然后是操作

在程序或脚本那里填入PowerShell的地址 把刚刚保存的PowerShell脚本的地址填到参数那里 但注意前面还有一个 - File 参数 
到这里大概就差不多了其他的可以再看看
可以在选择触发时间的时候选择一两分钟后试试可不可以运行,反正我的可以😎
现在,终于可以不用手敲命令了🤣
终 ~
|