You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We usually have some experiment code that we don’t want they to step into our commit. I usually mark my experiment with // but sometimes forget to unstage that
Starting with 2.9, Git has improvement on its commit hook which makes it globally using hooksPath
Create pre-commit file
Create a file called pre-commit, and place it into, for example /Users/khoa/hooks
#!/bin/sh# https://appventure.me/2016/04/04/prevent-accidental-test-code-commits/if git rev-parse --verify HEAD >/dev/null 2>&1then
against=HEAD
else# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi# The special marker tag to mark things which we still need to change
marker="<TEST>"# Redirect output to stderr.exec1>&2iftest$(git diff --cached -z $against| grep $marker| wc -c)!= 0
then
cat <<\EOF Error: Still has invalid debug markers in code:EOFecho`git diff --cached -z $against -G $marker`exit 1
fi
Apply the hook
In your project, run git config core.hooksPath /Users/khoa/hooks
That’s it. Whenever you commit a file with that pattern, it won’t let you commit
How to use
Try
// <TEST>
UserManager.shared.isActive =true
and git commit -m "my commit message" will assert with Error: Still has invalid debug markers in code:
Uh oh!
There was an error while loading. Please reload this page.
Original post https://medium.com/@onmyway133/check-before-you-commit-5a7601cffc87
We usually have some experiment code that we don’t want they to step into our commit. I usually mark my experiment with // but sometimes forget to unstage that
Starting with 2.9, Git has improvement on its commit hook which makes it globally using hooksPath
Create pre-commit file
Create a file called
pre-commit
, and place it into, for example/Users/khoa/hooks
Apply the hook
In your project, run
git config core.hooksPath /Users/khoa/hooks
That’s it. Whenever you commit a file with that pattern, it won’t let you commit
How to use
Try
and
git commit -m "my commit message"
will assert withError: Still has invalid debug markers in code:
Reference
The text was updated successfully, but these errors were encountered: