简体   繁体   English

Git提交前提交钩子添加文件

[英]Git Pre-Commit Hook Adding File After Commit

I am attempting to dump a mysql database and add the .sql dump file to the staging area using a pre-commit hook so it can then be included in the commit (on Windows Server 2012 R2/IIS). 我正在尝试转储mysql数据库并使用预提交钩子将.sql转储文件添加到暂存区域,以便随后可以将其包含在提交中(在Windows Server 2012 R2 / IIS上)。 The following code dumps the database nicely, but after I commit it still shows the be.sql file in the staging area...sometimes(?) - it seems to be adding the file to staging AFTER committing(?). 下面的代码很好地转储了数据库,但是在我提交之后,它仍然在临时区域中显示be.sql文件……有时(?)-似乎是在提交commit((?)之后将文件添加到临时中。 This is a pre-commit hook so I have no idea why it may be adding the file after the commit takes place: 这是一个预先提交的钩子,所以我不知道为什么在提交之后它可能会添加文件:

#!/bin/bash

# Dump Database
/c/Program\ Files\ \(x86\)/MySQL/MySQL\ Server\ 5\.7/bin/mysqldump.exe -u root --skip-extended-insert be > /c/inetpub/wwwroot/directory/be/be.sql

# Add Database
cd /c/inetpub/wwwroot/directory/be
git add be.sql

The behavior is a bit strange - I will see be.sql is still in the staging area so I will make a commit. 行为有点奇怪-我将看到be.sql仍在登台区域中,因此我将进行提交。 If I git status afterwards the tree is clean. 如果之后我发出git状态,那棵树就干净了。 If I commit again and git status it will display the be.sql file in the staging index as modified (I didn't modify it). 如果我再次提交并处于git status状态,它将在登台索引中显示修改后的be.sql文件(我没有对其进行修改)。 And back and forth it goes. 来回走。 I just want it to dump the .sql file, add the .sql file to the staging index, THEN commit so every time the staging index is clean. 我只希望它转储.sql文件,然后将.sql文件添加到登台索引中,然后提交,以便每次登台索引都干净时。 Any ideas as to why this is happening would be greatly appreciated. 任何关于为什么发生这种情况的想法将不胜感激。

Using: 使用:

git commit -m "Message" --allow-empty

when making the commit appears to have worked. 进行提交时似乎起作用了。 It seems as if git needs other staged changes in order for the hook to work. 好像git需要其他分阶段的更改才能使该钩子起作用。 So it was basically not making the commit, but still dumping the be.sql file, which would then show up in the staging index as modified the next time around because the date had changed. 因此,它基本上不是在进行提交,而是仍在转储be.sql文件,该文件随后将在登台索引中显示为下次修改,因为日期已更改。 In order to allow the commit to fully go through regardless of whether or not there were other staged changes I used the --allow-empty option, which allows a commit with nothing in the staged index. 为了使提交完全通过,无论是否进行了其他分段更改,我使用了--allow-empty选项,该选项允许在分段索引中不包含任何内容的提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM