Windows 计划任务到 git push 到 github

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6770044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:31:06  来源:igfitidea点击:

Windows scheduled task to git push to github

windowsgitgithubmsysgit

提问by PokerIncome.com

I hope to add a Windows Scheduled Task to git push to github every night. I have a CMD file. When I run the CMD file on the windows command prompt, it works fine. But when I run it via windows scheduled task. It's stuck forever. The status is "running". And from the log I can see it successfully started the git bash shell. Any idea?

我希望每晚添加一个Windows计划任务到git push到github。我有一个 CMD 文件。当我在 windows 命令提示符下运行 CMD 文件时,它工作正常。但是当我通过 Windows 计划任务运行它时。它永远卡住了。状态为“正在运行”。从日志中我可以看到它成功启动了 git bash shell。任何的想法?

echo git push > i:\gitpush
echo 'pushing' >>log1
C:\WINDOWS\SysWOW64\cmd.exe  /c ""C:\Program Files (x86)\Git\bin\sh.exe" --login i:\gitpush" >>log1 2>>error    
echo 'done pushing' >>log1
del i:\gitpush

Here is the log output:

这是日志输出:

'pushing'
Welcome to Git (version 1.7.4-preview20110204)


Run 'git help git' to display the help index.
Run 'git help <command>' to display help for specific commands.

Then I did an experiment to rename gitpush script to a wrong file name. And it exited immediately with the error "No such file or directory", which is expected. It shows the gitpush script is passing in correctly to the bash but for some reason it's stuck.

然后我做了一个实验,将 gitpush 脚本重命名为错误的文件名。它立即退出并出现错误“没有这样的文件或目录”,这是预期的。它显示 gitpush 脚本正确传递给 bash,但由于某种原因它被卡住了。

The reason I have to go through git bash shell is because I don't know how to setup public key in windows command line shell without using git bash shell.

我必须通过 git bash shell 的原因是因为我不知道如何在不使用 git bash shell 的情况下在 windows 命令行 shell 中设置公钥。

Thanks!

谢谢!

采纳答案by VonC

I don't know how to setup public key in windows command line shell

我不知道如何在 windows 命令行 shell 中设置公钥

Public/private keys work also in a DOS shell, provided you define the %HOME%environment variable (referencing the parent directory of the .ssh)

公钥/私钥也可以在 DOS shell 中工作,前提是您定义了%HOME%环境变量(引用 的父目录.ssh

The trick with Windows Scheduled Task is to make sure:

Windows 计划任务的技巧是确保:

  • whois actually running the task (the "system account"? or the actual user?)
    Displaying "env" can help debugging the issue.
  • whereit is run: if git push depends on the current path to properly push the current repo, you need to be certain that your task runs where it is supposed to.
  • 在实际运行任务(“系统帐户”?还是实际用户?)
    显示“ env”可以帮助调试问题。
  • 在哪里运行:如果 git push 依赖于当前路径来正确推送当前 repo,你需要确定你的任务在它应该运行的地方运行。