How to exclude blade files from git diff command?

Viewed 89

I have below command to get files and I want to exclude all .blade.php files.

$(git diff --cached --name-only --diff-filter=ACM | grep ".php\{0,1\}$")

How can I do that?

I tried these ways :

  1. $(git diff --cached --name-only --diff-filter=ACM | grep --exclude="*\.blade.php*"| grep ".php\{0,1\}$")
    
  2. $(git diff --cached --name-only --diff-filter=ACM | grep --exclude="*\.blade.php*" ".php\{0,1\}$")
    

but none of the above is working.

1 Answers

One is to use grep -v to exclude files that match a pattern.

git diff --cached --name-only --diff-filter=ACM | grep ".php\{0,1\}$" | grep -v '.blade.php$'

The other is to exclude the files in git diff.

git diff --cached --name-only --diff-filter=ACM -- . ':!*.blade.php' | grep ".php\{0,1\}$"

-- . ':!*.blade.php' means all files excluding those that match the pattern *.blade.php under the current folder.

Related