如何配置自动推送?

Joh*_*ler 9 git mercurial

如何在Mercurial和Git中配置自动推送?有时我忘记推入计算机,当我移动我的位置时,我与好的代码无法同步.例如,有没有办法让mercurial和git每小时都这样做?

Man*_*dan 20

使用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 
Run Code Online (Sandbox Code Playgroud)

Where remote指的是您要推送的远程仓库的名称.

cron如果您愿意,您还可以设置每小时执行此脚本.

更新

Mercurial也有钩子(但当然).这是相关文档.我没有使用Mercurial,所以你必须自己解决.

  • `-f`非常危险.不要那样做. (3认同)
  • - 镜子非常危险,我不确定这是你想要的.如果你不是最新的,你会粉碎其他人的变化. (2认同)

Ry4*_*ase 9

在mercurial你会把它放在你的 .hg/hgrc

[hooks]
commit = hg push
Run Code Online (Sandbox Code Playgroud)