gpt4 book ai didi

git - 如何使用 git 和 git hooks 同步数据库以及如果它不起作用如何调试

转载 作者:行者123 更新时间:2023-11-29 03:42:05 24 4
gpt4 key购买 nike

在操作系统上:Ubuntu 12.04

我的服务器上有一个 drupal 部署(实时网站)和一个暂存环境(测试网站)。每次我从暂存网站提取更改时,我都希望按照此处的说明自动同步数据库:http://ben.kulbertis.org/2011/10/synchronizing-a-mysql-database-with-git-and-git-hooks/

我使用的设置完全相同(当然,设置和路径根据我的设置而定)。

引自网站:

Let’s start with pre-commit. The pre-commit hook will run a script directly before a commit is executed. To edit your pre-commit hook:

[your editor] /path/to/your/repo/.git/hooks/pre-commit

Now, lets write the pre-commit script. We are going to tell the system to dump our MySQL database to our git repository and add it to be committed.

#!/bin/sh
mysqldump -u [mysql user] -p[mysql password] --skip-extended-insert [database] > /path/to> /your/repo/[database].sql
cd /path/to/your/repo
git add [database].sql

Now, lets write the post-merge script. We are going to tell the system to restore the MySQL dump to the local database for the latest changes. Edit the post-merge hook with:

[your editor] /path/to/your/repo/.git/hooks/post-merge

And write:

#!/bin/sh
mysql -u [mysql user] -p[mysql password] [database] < /path/to/your/repo/[database].sql

但是当我提交然后 pull 时,似乎什么也没有发生。 merge 后和提交前 Hook 位于部署存储库的我的 Hook 目录中,我从中进行提交和 pull 。两者都有执行权限:chmod +x/path/to/hook

我已经测试了放置在 Hook 中的命令。它们应该可以正常工作。

有什么方法可以调试错误吗?

最佳答案

对于“post-merge”,如果您运行“git pull”并且已经是最新的,那么“post-merge' 钩子(Hook)不会运行。

如果您的存储库中的文件没有更改,“pre-commit” Hook 似乎会运行。只需确保脚本中任何命令后没有空格即可。

这真的很令人失望,我希望看到一个“pre-pull” Hook 和一个“pre-commit” Hook ,无论对存储库。

话又说回来,我不是开发人员,所以我可能在这里遗漏了一些东西。 . .

编辑:只是测试一下以确保我做对了。

关于git - 如何使用 git 和 git hooks 同步数据库以及如果它不起作用如何调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12573883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com