[英]Git: is there a way to auto push a subtree?
I have a big private repository which is maintained on a local network.我有一个在本地网络上维护的大型私有存储库。 I'd like to automatically push a subtree of that repository outside of that network.
我想自动将该存储库的子树推送到该网络之外。 I need it to be simple:
我需要它很简单:
*Task* someone pushes to local remote repository --> a subtree is automatically pushed to some other repository *任务*某人推送到本地远程存储库 --> 子树会自动推送到其他某个存储库
I am not sure if this could be achieved with a server side hook because AFAIK there is no such thing as pushing subtrees from bare remotes.我不确定这是否可以通过服务器端挂钩来实现,因为 AFAIK 没有从裸遥控器推送子树这样的事情。 I came up with two ideas:
我想出了两个想法:
post-commit-hook
and make every user install it, but this is terrible, isn't it?post-commit-hook
并让每个用户都安装它,但这很糟糕,不是吗? Git book specifically states that policies should be enforced on server side . Is there a simple way of achieving something like this?有没有一种简单的方法可以实现这样的目标? Or is this impossible and it's just git abuse?
或者这是不可能的,这只是 git 滥用?
Umm, I'm a bit embarrassed.嗯,我有点不好意思。 Apparently this was much easier than I thought.
显然这比我想象的要容易得多。 Here is a hasty solution which builds on @wrzasa suggestion:
这是一个基于@wrzasa建议的草率解决方案:
Clone your repository on the server to which you are pushing, like this (dir.git is a bare repo):在您推送到的服务器上克隆您的存储库,如下所示(dir.git 是一个裸存储库):
. |- dir.git |- dir
In dir
do: git remote add <remote-name> <remote-address>
在
dir
执行: git remote add <remote-name> <remote-address>
In dir.git/hooks/post-receive
put:在
dir.git/hooks/post-receive
:
#! /bin/bash unset GIT_DIR cd ../dir git pull ../dir.git git subtree split --prefix=<subdir-in-dir> --branch=<branch-name> git push <remote-name> <branch-name>
Remember to make post-receive
executable.请记住使
post-receive
可执行。 See this answer if you wanna know why unset GIT_DIR
is needed.如果您想知道为什么需要
unset GIT_DIR
请参阅此答案。
That's pretty much it.差不多就是这样。 Now whenever someone pushes to
dir
remote (ie dir.git
) subtree under <subdir-in-dir>
will be pushed to <remote-name>
.现在,每当有人推送到
dir
remote(即dir.git
)时, <subdir-in-dir>
下的子树将被推送到<remote-name>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.