Prevent `git` from pushing commits with this commit message

How to prevent git from total commits that contain a given string in commit mode, for example, "DO NOT BUY"?

Context / UseCase:

My typical workflow: I crack the hack, breaking the work into microcommands, when I work, I rewrite the history, changing the order of fixation, to group them intelligently, and then crush them into more meaningful details. When the work is ready, everything will be ready to click!

Now, I would like git to stop me from accidentally getting into the repository commits, which are still ongoing. I believed that holding the message "DO NOT LET" as part of a commit message. How to make git automatically stop me from pushing when it reaches that commit after git push?

(On for pre-receive solutions: consider github as an example of a service that AFAIK does not allow to intercept recipes , with the exception of its Enterprise edition)

+4
source share
1 answer

You can use a hook pre-push, but this remains a local hook that can be circumvented.
See This Pre-Click Example, which scans each commit message.

# Check for foo commit
        commit=`git rev-list -n 1 --grep '^foo' "$range"`
        if [ -n "$commit" ]
        then
echo "ERROR: git pre-push hook found commit message starting with 'foo' in $local_ref"

pre-receive hook . , . ( , , GitHub, BitBucket GitLab.com)

+4

Source: https://habr.com/ru/post/1668848/


All Articles