Created
August 3, 2020 12:40
-
-
Save wotta/774d87660a156cd1934688fb856f3afe to your computer and use it in GitHub Desktop.
GIT Ignore specific line from commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This hook will look for code comments marked '//no-commit' | |
# - case-insensitive | |
# - dash is optional | |
# - there may be a space after the // | |
# | |
noCommitCount=$(git diff --no-ext-diff --cached | egrep -i --count "(@No|\/\/\s?no[ -]?)commit") | |
if [ "$noCommitCount" -ne "0" ]; then | |
echo "WARNING: You are attempting to commit changes which include a 'no-commit'." | |
echo "Please check the following files:" | |
git diff --no-ext-diff --cached --name-only -i -G"(@no|\/\/s?no-?)commit" | sed 's/^/ - /' | |
echo | |
echo "You can ignore this warning by running the commit command with '--no-verify'" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Resource: https://stackoverflow.com/questions/16244969/how-to-tell-git-to-ignore-individual-lines-i-e-gitignore-for-specific-lines-of#answer-20574486