在预提交钩子期间git diff导致不是git仓库 [英] git diff during pre-commit hook results in Not a git repository
本文介绍了在预提交钩子期间git diff导致不是git仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在git中构建一个预先提交的脚本。在该脚本中,我计划在某个文件夹发生更改时运行任务。测试,在我的脚本中,我有
git diff --cached | grep -q^ my / folder
结果是...
不是git存储库
比较工作树之外的两条路径:
usage:git diff [--no-index] <路径> <路径>
pwd
目录和 $ GIT_DIR
是 .git
。我引导相信
解决方案
即使设置了GIT_DIR,我仍然会尝试:
pre $ g $ c $ git git -dir = / full / path / to / repo / .git --work-tree = / full / path / to / rpeo diff --cached | grep -q^ my / folder
这样,你确定该钩子被执行的地方。
I'm trying to build a pre-commit script in git. In that script I plan on running tasks if a certain folder has changed. To test, in my script I have
git diff --cached | grep -q "^my/folder"
This results in...
Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>
pwd
says I'm in the correct directory and $GIT_DIR
is .git
. I was lead to belive that --cached
was the special sauce to get this working in a hook. Is there a way to do this?
解决方案
Even though GIT_DIR is set, I would still try a:
git --git-dir=/full/path/to/repo/.git --work-tree=/full/path/to/rpeo diff --cached |grep -q "^my/folder"
That way, you are sure the hook is executed where it is supposed to.
这篇关于在预提交钩子期间git diff导致不是git仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文