GIT钩子post-receive和远程仓库git pull [英] GIT hook post-receive and remote repository git pull

查看:140
本文介绍了GIT钩子post-receive和远程仓库git pull的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究如何通过使用GIT post-receive hook来实现以下场景。



我有三个远程存储库位于不同的远程服务器上。 / p>

服务器A,服务器B和服务器C



我想将我的工作推送到服务器A,服务器A上的post-receive挂钩会自动执行服务器B和C的GIT pull以同时更新其存储库。

我已经测试了这个场景在我的本地PC中,通过在同一台计算机上创建三个不同的存储库来模拟三个远程服务器存储库。到目前为止,它工作正常,但是当我将此想法应用于远程存储库时,这非常困难。



我想知道是否有人知道如何实现这种情况下,或者如果你有任何想法或经验在这一个。



您的帮助将不胜感激。



感谢
Finau

解决方案

如果我正确地阅读了您的问题,服务器B 服务器C 要备份服务器A ,对吧?



在这种情况下,您不必告诉服务器B 服务器C A 取消$ c>到拉,而是从 A B C 。因此,您的post-receive钩子的内容将是

  git push --mirror server_b 
git push --mirror server_c

假设 server_b server_c A 上的已知远程。查看 git push - 镜像标志的描述。



如果你想 B C 成为活动部分,将cron作业设置为 git fetch A 定期执行。




另一种方法是在本地仓库中定义一个远程站点,其中包含三个URL:

  [remotemulti] 
url = server_a / repo.git $ b $ url url = server_b / repo .git
url = server_c / repo.git

现在,当您通常推动您的工作到 A 使用 git push ,只需做一个

  git push --mirror multi 

将所有本地 A B C






另一个问题是:为什么要推到 B C 呢?这似乎只是为了备份的原因。你是否知道每个回购(你的工作副本,> ,...)都包含你的发展的完整历史记录?这不像SVN,你有一个中心历史。 Git是一个DVCS,每个工作副本都有完整的历史记录。

因此,使用Git时,如果 all repos获得的历史记录只会丢失同时销毁。否则,您将始终至少有一个包含项目历史记录的回购。

另请参阅关于
Pro Git 的介绍一章。 b $ b

I'm currently investigating of how to achieve the following scenario by using GIT post-receive hook.

I have three remote repository sitting on different remote servers.

Server A, Server B and Server C

I want to push my work to Server A, and also use the post-receive hook on server A to automatically execute a GIT pull from Server B and C to updated their repository as well at the same time.

I already test this scenario in my local PC, by create three different repository at the same computer to mimic the three remote server repository. So far, it works fine, but when I take this idea to apply to a remote repository, it's quite hard.

I was wondering if there's anyone who knows how to achieve this scenario, or if you have any thoughts or experience on this one.

Your help will be much appreciated.

Thanks Finau

解决方案

If I read your question correctly, the only purpose of Server B and Server C is to backup Server A, right?

In that case, you don't have to tell Server B and Server C to pull from A, instead push from A to B and C. So the content of your post-receive hook would be

git push --mirror server_b
git push --mirror server_c

assuming that server_b and server_c are known remotes on A. See the docs of git push for a description of the --mirror flag.

If you want B and C to become the active part, set up a cron job to git fetch A periodically.


Another approach is to define a remote in your local repo that has three URLs:

[remote "multi"]
url = server_a/repo.git
url = server_b/repo.git
url = server_c/repo.git

Now, when you usually push your work to A using git push, simply do a

git push --mirror multi

to push all your local on A, B and C at the same time.


Another question is: why do you push to B and C at all? It seems as you are doing it just for backup reasons. Do you know that every repo (your working copy, that one on A, ...) contains a full history of your development? It's not like SVN where you have one central history. Git is a DVCS and every working copy has a full history.

So, using Git, your history will only get lost if all repos get destroyed at the same time. Otherwise, you'll always have at least one repo that contains your project history. See also the introduction chapter on Pro Git for some notes about that.

这篇关于GIT钩子post-receive和远程仓库git pull的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆