#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
/usr/local/opt/mysql/bin/mysqldump -uroot -p111111 -S /tmp/mysql-3306.socket dbname --no-data > path/to/dbfile/dbname.sql
git add path/to/dbfile/dbname.sql
pre-commit git hook
在你的repo根目錄應該有目錄
.git/hooks/
(需要先顯示隱藏目錄) , 在其中新建一個檔案pre-commit(目前使用者需要有執行權限),內容大致如下:上述mysql使用者、密碼、dbname都要變成你自己的。
支持@samoay 的答案。
但有一點提示,pre-commit的鉤子是客戶端的鉤子。
如果你的共同開發者需要用,你要把這個鉤子檔案複製給他們。
git hooks
是你的好夥伴