简体   繁体   中英

GIT (HUSKY): exit code when a file is being committed?

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.

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 smudge script is applied on during a git 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.

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