简体   繁体   中英

git diff during pre-commit hook results in Not a git repository

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.

unset GIT_DIR cleared it up. I'm disappointed that --git-dir did not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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