我使用的是windows7,但我认为这不算,因为钩子使用的是git shell。我尝试使用以下代码通过提交来转储我的数据库,但它不起作用。
#!/bin/sh
# Refresh the SQL schema file for inclusion within the git commit
# If something fails, exit with status other than 0
set -e
# select dump directory
cd $(git rev-parse --show-toplevel)
cd WebShop/DataBase
# first, remove our original schema
rm -f backup.sql
# generate a new schema
mysqldump -u root --password=root webshopdb > backup.sql
# Add the schema to the next commit
git add backup.sql
# Exit success
exit 0我收到两条错误消息:
该路径不存在,因为目录名称中的空格将其断开。
cd $(git rev-parse --show-toplevel)找不到命令
mysqldump -u root --password=root webshopdb > backup.sql有没有可能修复它?
发布于 2012-02-11 12:06:20
我修复了错误,它会创建sql文件,但仍然不会将其添加到提交中。我不知道为什么。
固定代码:
#!/bin/sh
# Refresh the SQL schema file for inclusion within the git commit
# If something fails, exit with status other than 0
set -e
# select dump directory
cd "$(git rev-parse --show-toplevel)"
# first, remove our original schema
rm -f "WebShop\DataBase\backup.sql"
# generate a new schema
exec "C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" --skip-comments -u root --password=root webshopdb |sed 's$),($),\n($g' > "WebShop\DataBase\backup.sql"
# Add the schema to the next commit
git add "WebShop\DataBase\backup.sql"
# Exit success
exit 0
发布于 2013-05-05 21:25:04
我也在尝试这样做,结果好坏参半,但最终还是奏效了。也许git自去年以来已经有了一些更新,解决了这个问题?也许是因为我用的是mac?下面是我现在使用的pre-commit。(感谢大家的帮助)
#!/bin/sh
# Dump a fresh copy of the database
mysqldump -u root --password="password" myDB --skip-extended-insert > dump.sql
git add dump.sql注意:--skip-extended-insert不是对bash进行任何更改所必需的,我只是喜欢在添加了额外选项的git中跟踪我的SQL转储的方式。
重要的是我是如何运行命令的
如果我从命令行运行git,那么就没有问题了。
如果我通过SourceTree运行git,则会出现错误unless SourceTree is run from the commandline too.
发布于 2012-02-11 06:27:25
要调试sh,请使用
sh -x script(评论set -e)
并且您可以在开始时编写rc文件,以避免使用完整路径:
source ~/.shrchttps://stackoverflow.com/questions/9235682
复制相似问题