简体   繁体   English

将数据推送到裸git仓库时,如何自动将数据推送到git-repo?

[英]How can I automatically push the data to a git-repo when it's pushed to a bare git repo?

How can I automatically push the data to a git-repo when it's pushed to a bare git repo? 将数据推送到裸git仓库时,如何自动将数据推送到git-repo?

gitrepo - the name of my bare repo, I push to this repo from my desktop
sandbox - the name of a git repo, should automatically contain up-to-date data

After each push to gitrepo, the sandbox repository should automatically contain up-to-date data. 每次推送到gitrepo后,沙箱存储库应自动包含最新数据。

I considered not using a bare repository and directly push to the sandbox, it's impossible to push to a non-bare git repository. 我考虑过不使用裸仓库,而是直接推送到沙箱,不可能推送到非裸git仓库。 So the solution people recommended was a post-receive hook that will make the data available under /etc/puppet/environments/sandbox/. 因此,人们推荐的解决方案是一个接收后挂钩,该挂钩将使数据在/ etc / puppet / environments / sandbox /下可用。

[root@puppet environments]# cat gitrepo/hooks/post-receive
#!/bin/sh
cd /etc/puppet/environments/sandbox/
git pull origin
[root@puppet environments]#

Unfortunately this hook doesn't do anything either. 不幸的是,这个钩子也没有任何作用。 I have looked at the example ( http://utsl.gen.nz/git/post-update ) offered at http://bare-vs-nonbare.gitrecipes.de/ , but I can hardly believe such a simple thing as automatically pushing the repo-commits to another repo should need 86 lines of code. 我看了http://bare-vs-nonbare.gitrecipes.de/提供的示例( http://utsl.gen.nz/git/post-update ),但我简直不敢相信像自动将回购提交提交到另一个回购应该需要86行代码。

When you're in some (or maybe even all) of the various git hooks, definitely including post-receive , the environment variable GIT_DIR is set to . 当您使用各种git钩子中的某些(或什至全部)钩子(肯定包括post-receive ,环境变量GIT_DIR设置为. (!), which means that if you use cd /etc/puppet/environments/sandbox and run any further git command it will look for the repo in /etc/puppet/environments/sandbox , even though if that's a non-bare repo its git-managed contents are actually in /etc/puppet/environments/sandbox/.git . (!),这意味着如果您使用cd /etc/puppet/environments/sandbox并运行其他git命令,它将在/etc/puppet/environments/sandbox寻找该存储库,即使这是一个非裸露的存储库它的git管理的内容实际上位于/etc/puppet/environments/sandbox/.git

Your simple test-hook will likely start working for you (making it work for others is harder) if you simply add: 如果您简单地添加以下内容,则简单的测试钩可能会开始为您服务(使其更难以为他人使用):

unset GIT_DIR

before using git commands. 在使用git命令之前。

(Note that blindly doing a git pull is effective but overkill if the most recent push was, eg, to a side-project branch, or was done to add a tag, or any other operation that leaves the sandbox's branch untouched.) (请注意,盲目地执行git pull是有效的,但如果最近的推送是例如到side-project分支,添加标签或执行任何其他使沙盒分支保持不变的操作,则可能会造成过度杀伤。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM