简体   繁体   English

致命:不是git存储库:'。git'错误

[英]fatal: Not a git repository: '.git' error

I have created a pre-commit hook which takes the database dump and saves it in a file under my application/folder which is also in the git repo, after saving it I add the file to commit list . 我创建了一个预提交钩子,它接受数据库转储并将其保存在我的应用程序/文件夹下的文件中,该文件也在git repo中,保存后我将文件添加到提交列表中。 Following is the code in my pre-commit file 以下是我的预提交文件中的代码

    D:/xampp/mysql/bin/mysqldump -u root -pxyz --skip-extended-insert [database] > D:/xampp/htdocs/app/application/[database].sql

cd D:/xampp/htdocs/app/application
git add [database].sql

I tried to run the pre-commit code directly through command prompt it works without any error but when I try to commit the code through git bash I get this error 我尝试直接通过命令提示符运行预提交代码,它没有任何错误,但当我尝试通过git bash提交代码时,我得到此错误

fatal: Not a git repository: '.git' 

I am assuming its because of the git command used in the pre-commit file, can anyone tell me whats wrong in this file and how I should amend it 我假设它是因为预提交文件中使用的git命令,任何人都可以告诉我这个文件中有什么错误以及我应该如何修改它

In doubt, in your hook, set up explicitly git-dir and work-tree parameters: 有疑问,在你的钩子中,明确设置git-dirwork-tree参数:

git --git-dir .git --work-tree . add ...

You can even put the full path to be extra-sure: 你甚至可以把完整的路径放在一边:

git --git-dir D:/xampp/htdocs/app/application/.git --work-tree D:/xampp/htdocs/app/application/. add ...

That way, you rule out any environment issue with those git-dir or work-tree stuck into another path which isn't the one of the repo your are cd'ing into. 这样,你排除任何环境问题,那些git-dirwork-tree插入到另一个路径中,而这个路径不是你正在进行的repo之一。
See " Calling ' git pull ' from a git post-update hook " for an example of that problem. 有关该问题的示例,请参阅“ git post-update挂钩调用' git pull ' ”。

i had the exact same issue like you and found this solution: 我和你一样有同样的问题并找到了这个解决方案:

instead of doing 而不是做

cd D:/xampp/htdocs/app/application
git add [database].sql

i simply did 我干脆做了

git add D:/xampp/htdocs/app/application/[database].sql

that way i didn't irritate git by cd-ing into another folder :) 这样我就不会因为进入另一个文件夹而激怒git :)

make sure you're in directory which have .git folder ? 确保你在目录中有.git文件夹? to make sure, try to run 确保,尝试运行

git status

and see what's happen. 看看会发生什么。 if you still get such message, I think your git hasn't been set up yet. 如果你仍然收到这样的消息,我认为你的git还没有设置好。

follow those steps to set up it: 按照以下步骤进行设置:

git init
git add .
git commit -m "your message"
git push

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

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