问题描述
使用外部Subversion版本库的一个副作用是每次提交都会自动进行异地备份。
我想用Git实现同样的效果。
即对本地存储库的每一次提交都会自动提交给外部存储库,因此这两个存储库始终保持同步。
我想象一下post-commit钩子是要走的路。有没有人有这方面的具体例子?
我为此写了一个post-commit钩子。钩本身很简单,只需在 .git / hooks /
目录中添加一个名为 post-commit
的文件,其内容如下:
git push my_remote
post-commit
文件应该是可执行文件。另外请确保您添加了合适的 my_remote
这个钩子才起作用。
后提交
。这是可选的。如果你这样做,你会在合并后自动同步。 更新:如果您想确保您的服务器和您的镜像不会不同步,并确保所有分支也都备份后,你的后提交
钩子可以使用:
git push my_remote -f --mirror
One of the side-effects of using an external Subversion repository was getting automatic offsite backups on every commit.
I'd like to achieve the same using Git.
i.e. every commit to my local repository automatically commits to an external one so the two repositories are always in sync.
I imagine that a post-commit hook would be the way to go. Does anyone have any specific examples of this?
I wrote a post-commit hook for just this purpose. The hook itself is simple; just add a file named post-commit
to your .git/hooks/
directory with the following contents:
git push my_remote
The post-commit
file should be executable. Also make sure that you add a suitable remote repository with the name my_remote
for this this hook to work.
I also made a symlink named post-merge
that points to post-commit
. This is optional. If you do this you'll auto-sync after merges as well.
UPDATE: If you want to ensure that your server, and your mirror do not get out of sync, and ensure that all branches are also backed up, your post-commit
hook can use:
git push my_remote -f --mirror
这篇关于自动镜像一个git仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!