预提交脚本创建mysqldump文件,但是“没有提交(工作目录干净)”? [英] Pre-commit script creates mysqldump file, but "nothing to commit (working directory clean)"?

查看:214
本文介绍了预提交脚本创建mysqldump文件,但是“没有提交(工作目录干净)”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用脚本.git / hooks / pre-commit将MySQL数据库的快照和其他项目文件一起使用。这里是内容:

 #!/ bin / bash 
mysqldump -u用户-ppassword --skip-extended -insert dbname> /path/to/repo/dbname.sql
cd / mnt / hoste / Storage / Code / test-repo /
git add /path/to/repo/dbname.sql
code>

如果我运行:

  git commit -amMessage

创建一个新的转储文件,但随后git告诉我:

 没有提交(工作目录干净)

然后,如果我再次运行相同的提交命令,它可以工作:

  1文件更改,1插入(+),1删除( - )

然后,如果我运行相同再次命令,回到没有提交。这种模式继续无限 - 工程,不工作,工作,不起作用。这不是基于时间(我已经尝试立即提交,并等待10分钟)。 mysqldump当然会更新.sql文件(它的日期在文件末尾用hh:mm:ss格式标记)。



如果我把脚本和在命令行中逐行运行它(包括首先进入钩子目录以完全模拟运行脚本),每次都有一个新的提交。如果我将它放入可执行文件中的钩子或repo root中,并从命令行执行它,然后运行commit命令,则它每次都有效。它只能在每隔一段时间才工作,然后才从预先提交中运行。



什么可能导致这种奇怪的行为?

解决方案

在一个钩子中,确保始终指定git_dir和work_tree:

<$ p $你的/你的/ repo / .git --work-tree = / path / to / your / repo add - yourFile
code>

通过改变钩子文件夹,你不会改变当前的git仓库。如果该回购协议应该改变,最好明确地使用 - git-dir 选项来引用它。


I'm using the script .git/hooks/pre-commit to take snapshots of a MySQL database along with other project files. Here are the contents:

#!/bin/bash
mysqldump -u user -ppassword --skip-extended-insert dbname > /path/to/repo/dbname.sql
cd /mnt/hoste/Storage/Code/test-repo/
git add /path/to/repo/dbname.sql

If I run:

git commit -am "Message"

A new dump file is created, but then git tells me:

nothing to commit (working directory clean)

Then, if I run the identical commit command again, it works:

1 file changed, 1 insertion(+), 1 deletion(-)

Then, if I run the identical command again, back to "nothing to commit". This pattern continues ad infinitum - works, doesn't work, works, doesn't work. It's not based on time (I've tried commit immediately, and waiting 10 minutes). Mysqldump is certainly updating the .sql file (it date stamps them with hh:mm:ss format near the end of the file).

If I take the script, and run it line by line at the command line (including first cd'ing to the hooks directory to fully simulate running the script), there is a new commit every time. If I put it in an executable file in hooks, or in repo root, and execute it from command line, and then run the commit command, it works every time. It only doesn't work every other time, and then only when it's run from within pre-commit.

What could be causing this weird behaviour?

解决方案

In a hook, make sure to always specify the git_dir and work_tree:

git --git-dir=/path/to/your/repo/.git --work-tree=/path/to/your/repo add -- yourFile

By changing folder in a hook, you are not changing what was the current git repo. If that repo is supposed to change, it is best to reference it explicitly with the --git-dir option.

这篇关于预提交脚本创建mysqldump文件,但是“没有提交(工作目录干净)”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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