Last active
February 15, 2023 08:30
-
-
Save kunicmarko20/4ac45ae65d21eb524a7fc441f885712f to your computer and use it in GitHub Desktop.
Pre Commit Git hook that will remove file from commit if it contains "// warn-before-commit" string
This file contains hidden or 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 | |
top_level_path="$(git rev-parse --show-toplevel)"; | |
while read file_name; do | |
if grep -q "// warn-before-commit" "$top_level_path/$file_name"; then | |
git reset $file_name; | |
echo "File $file_name, was not commited because 'warn-before-commit' string was found." | |
fi | |
done < <(git diff --cached --name-only --diff-filter=ACM) |
Does this actually work for you? The files I reset still somehow get added to my commit. If I add
--soft
orgit restore --staged
it completely deletes the changes.
Hey, it used to work without a problem when I created it, but haven't used this in 2y for sure, so not sure if something changed around hooks potentially
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this actually work for you? The files I reset still somehow get added to my commit. If I add
--soft
orgit restore --staged
it completely deletes the changes.