问题
is there a way to check if a file is being committed and exit with an error ?
I have a file in git that needs to be there but should never be modified and i was hoping to use husky as a pre-commit - so if anybody tries to modify the file and commit then it would throw an error.
If in future I need to modify the file then i can just disable the pre-commit.
the file is a configuration that i need to edit a lot when developing but the changes should never be committed.
I was hoping to use husky as a check to ensure that i dont.
回答1:
I would rather manage sure a file with a content filter driver, using .gitattributes declaration.
That means you do not version the actual configuration file, but only a template file, and a file with all possible values per environment.
(image from "Customizing Git - Git Attributes", from "Pro Git book")
The generated actual file remains ignored (by the .gitignore): your actual working tree does not get "dirty".
The smudge script:
- detect the right environment (not the branch, since only one is needed)
- selects the correct value file and generates the correct file based on the template the
smudgescript is applied on during agit checkout.
That way, you modify the config.dev value file as much as you want when developing: the config file (not versioned) will be generated from those values.
But in production, a checkout of that same repo will trigger the generation of a prod config file, using the config.prod (versioned file) values.
来源:https://stackoverflow.com/questions/54140322/git-husky-exit-code-when-a-file-is-being-committed