用于在 git pull 上创建/添加数据库转储文件到存储库的钩子
我的目标是尽量减少本地克隆我的网站+数据库所需的步骤。
我在网络服务器上有一个中央 git 存储库和一个本地克隆。当我在本地计算机上拉取更新时,我不仅应该从远程存储库获取最新的文件版本,还应该在此 Web 服务器上运行脚本来转储实时数据库,并在交付拉取之前将其添加到存储库。
我的猜测是,当我在交付存储库之前在本地计算机上触发 git pull 时,我需要在远程计算机上执行以下操作:
- 创建数据库转储文件,例如 dump.sql (通过执行 mysqldump)
- 将 dump.sql 添加到存储库
- 将 dump.sql 提交到存储库
……然后才将拉取传递到本地计算机。
我应该为此使用什么样的 git hook? 我也很感激任何有关这种情况的额外经验。
My aim is to minimize the steps needed to locally clone my website + database.
I have a central git repository on a webserver and a local clone. When I pull updates on my local machine, not only should I get the latest file versions from the remote repository but also should a script run on this webserver to dump the live database and additionally add it to the repository prior to delivering the pull.
My guess is that I need the following actions to happen on the remote machine when I fire git pull on the local machine prior to delivering the repository:
- Create database dump file, e.g. dump.sql (by exectuting mysqldump)
- Add dump.sql to repository
- Commit dump.sql to repository
… and only then deliver the pull to the local machine.
What kind of git hook should I use for this?
I'd also appreciate any additional experience with such a scenario.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
git help hooks
列出了钩子的类型以及它们如何工作,但是没有一个钩子可以用来做你想做的事情(你需要类似pre-upload< /code> 将由 git-upload-pack 执行)。
但是,您可以在服务器上围绕 git-upload-pack 创建一个包装器脚本,该脚本执行必要的操作,然后执行真正的 git-upload-pack 命令:
git-upload-pack
可执行文件git-upload-pack.real
某处创建一个名为
执行以下操作:git-upload-pack
的新脚本code>PATHcd
进入 Git 存储库hooks/pre-upload
存在并且是可执行文件:git-upload-pack.real
git help hooks
lists the types of hooks and how they work, but there isn't a hook that you can use to do what you want (you'd need something likepre-upload
that would be executed bygit-upload-pack
).However, you could create a wrapper script around
git-upload-pack
on the server that performs the necessary actions and then executes the realgit-upload-pack
command:git-upload-pack
executablegit-upload-pack.real
git-upload-pack
somewhere inPATH
that does the following:cd
into the Git repositoryhooks/pre-upload
exists and is an executable file:git-upload-pack.real
with the original command-line argumentshooks/pre-upload
script in your Git repository that does whatever you want