简体   繁体   English

忽略 git hook 中的多个目录

[英]Ignore multiple directories in git hook

I want to ignore any dist and node_modules directories in my git commit hook.我想忽略我的 git commit 钩子中的任何distnode_modules目录。 I've tried this:我试过这个:

git diff --cached --name-only --diff-filter=ACM | find . -path ./node_modules -prune -o -path './**/dist -prune -o -name '*.js'

But it doesn't work.但它不起作用。 It doesn't seem like the find is accepting the files found from the git diff...似乎 find 不接受从 git diff 找到的文件...

If I run:如果我运行:

git diff --cached --name-only --diff-filter=ACM

I correctly get the staged files:我正确地得到了暂存文件:

./dist/some-file.js

And if I run:如果我运行:

find . -path ./node_modules -prune -o -path './**/dist' -prune -o -name '*.js' -print

I correctly get a list of files that don't include any that are in dist or node_modules directories.我正确地获得了不包含distnode_modules目录中的任何文件的列表。

How can I combine these do that my git hook doesn't pick up staged files in dist directories.我怎样才能将这些结合起来,以使我的 git 钩子不会在 dist 目录中拾取暂存文件。

find doesn't process its standard input, so it can't be used after | find不处理它的标准输入,所以它不能在|之后使用

grep can be used instead可以改用grep

| grep -v '/dist/' | grep -v '/node_modules/'

or using one grep process或使用一个 grep 进程

| grep -Ev '/dist/|/node_modules/'

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

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