3 ms·
I'd like to have some way to prevent certain code from being committed in the first place. E.g. when I have a line saying printf("debug: now at: %d\n", i)
by amelius 8y ago
I'd like to have some way to prevent certain code from being committed in the first place.
E.g. when I have a line saying
printf("debug: now at: %d\n", i); /* DONTCOMMIT */
then when I type "git commit ...", a script will be invoked that will recognize the "DONTCOMMIT" string, and it will abort the commit.
- wink 8y agoShould be possible if you create a pre-commit hook, like this one https://gist.github.com/guilherme/9604324 https://gist.github.com/guilherme/9604324
- amelius 8y agoHmm, it uses "git diff" but in my case, this shows a few lines of context. So if the context contains "console.log" (and not the change itself), the script would still complain.
- nextlevelwizard 8y agoLiterally what client side pre-commit and on server end post-commit scripts are for
- terhechte 8y agohttps://appventure.me/2016/04/04/prevent-accidental-test-code-commits/ https://appventure.me/2016/04/04/prevent-accidental-test-cod...
- lloeki 8y agoNitpick: this line if test $(git diff --cached -z $against | grep $marker | wc -c) != 0 may be changed to if git diff --cached -z $against | grep -q $marker
- lloeki 8y agoAs mentioned, should be doable with local or remote hooks. Additionally, GitLab has push rules[0] that help preventing pushing secrets (based on filenames). [0]: https://gitlab.adhoc-gti.com/help/push_rules/push_rules#prevent-pushing-secrets-to-the-repository https://gitlab.adhoc-gti.com/help/push_rules/push_rules#prev...
- pagade 8y agohttps://github.com/awslabs/git-secrets https://github.com/awslabs/git-secrets