混帐pre-承诺+ mysqldump的:无法找到路径,而不是现有的命令 [英] git pre-commit + mysqldump: cannot find path, not existing command

查看:573
本文介绍了混帐pre-承诺+ mysqldump的:无法找到路径,而不是现有的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Windows 7,但我认为这不算数,因为钩使用Git的外壳。我企图把我的数据库通过以下code提交,但没有奏效。

I have windows 7 but I think it doesn't count, because the hook uses git shell. I tried to dump my database by commit with the following code, but it did not work.

#!/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

我有2错误信息:

I've got 2 error messages:

的路径不存在的,因为在一个目录名空间弄坏。

The path doesn't exist, because the space in a directory name breaks it.

    cd $(git rev-parse --show-toplevel)

找不到命令

    mysqldump -u root --password=root webshopdb > backup.sql

是否有可能解决这个问题?

Is it possible to fix it?

推荐答案

我修复错误,它会创建SQL文件,但仍然没有将它添加到提交。我不知道为什么...

I fixed the errors, it creates the sql file, but still doesn't add it to the commit. I don't know why...

固定code:

#!/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


  • 如果我们在路径中有空格,我们必须加倍之间使用
    引号。

  • 我用exec和mysqldump.exe的完整路径,而不是
    mysqldump命令。

  • 通过制造mysqldump的选项一些变化:

    • 跳过注释(造成的创建时间页脚prevent文件变更)

    • 分裂中美战略经济对话
    • 插入多行

      这篇关于混帐pre-承诺+ mysqldump的:无法找到路径,而不是现有的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆