0

I have a sh file that runs pre-commit stage but I want to exclude some paths but I also want to know how to exclude files that ends with "*Test" for example.

Here's my sh file;

for FILE in `git-diff-index HEAD 2>&1 --name-only | sed 's/^:.*     //' | uniq` ; do

I know that this exclude path can be written with git-diff-index but I don't know how to write it.

Thanks

2 Answers 2

2

You can use magic pathspec to exclude some of the paths. For example

git diff-index HEAD -- :!*Test

would exclude all files that end with Test.

Minor compatibility note: do not use the dashed form git-diff-index, because support for it will be dropped; use the command form git diff-index.

Sign up to request clarification or add additional context in comments.

1 Comment

@dani Which part of the cited documentation is unclear? Are you looking for **?
0

git-diff-index HEAD 2>&1 --name-only -- . ':(exclude)*Tests.java' -- . ':(exclude)*Test.java' -- . ':(exclude)*\as\*' | sed 's/^:.* //' | uniq

This works well for both path and specific files

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.