我正在尝试在git中构建一个预提交脚本。在该脚本中,如果某个文件夹已更改,我计划运行任务。要测试,我的脚本中有
git diff --cached | grep -q "^my/folder"
这导致......
Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>
pwd
说我在正确的目录中,$GIT_DIR
是.git
。我感到相信--cached
是让这个工作在钩子里的特殊酱油。有没有办法做到这一点?
答案 0 :(得分:2)
即使设置了GIT_DIR,我仍然会尝试:
git --git-dir=/full/path/to/repo/.git --work-tree=/full/path/to/rpeo diff --cached |grep -q "^my/folder"
这样,你确定钩子在它应该的位置执行。
答案 1 :(得分:1)
unset GIT_DIR
清除了它。我很失望--git-dir
没有。