git 如何配置自动推送?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3839439/
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
How to configure automatic pushing?
提问by John John Pichler
How do I configure automatic push in Mercurial and Git? Sometimes I forgot to push in a computer, and when I move my location, I'm out of the sync with the good code. Is there a way to mercurial and git do this every hour, for instance?
如何在 Mercurial 和 Git 中配置自动推送?有时我忘记推入计算机,当我移动我的位置时,我与好的代码不同步。例如,有没有办法让 mercurial 和 git 每小时执行一次?
回答by Manoj Govindan
With git you can use the post-commit
hook to push after each commit. To do this you'll need to add an executable post-commit
script in your .git/hooks
directory. For e.g.
使用 git,您可以post-commit
在每次提交后使用钩子进行推送。为此,您需要post-commit
在.git/hooks
目录中添加一个可执行脚本。例如
#!/bin/sh
#
# An example hook script that is called after a successful
# commit is made.
#
# To enable this hook, rename this file to "post-commit".
git push --mirror remote
Where remote
refers to the name of the remote repo that you are pushing to.
Whereremote
指的是您要推送到的远程存储库的名称。
You can also setup cron
to execute this script every hour if you wish.
cron
如果您愿意,您还可以设置每小时执行一次此脚本。
Update
更新
Mercurial has hooks too (but of course). Here is the relevant documentation. I haven't used Mercurial so you'll have to work it out yourself.
Mercurial 也有钩子(当然)。这是相关文档。我没有使用过 Mercurial,所以你必须自己解决。
回答by Ry4an Brase
In mercurial you'd put this in your .hg/hgrc
在 mercurial 你会把它放在你的.hg/hgrc
[hooks]
commit = hg push