Skip to content

Instantly share code, notes, and snippets.

@jonas-johansson
Created November 28, 2022 14:05
Show Gist options
  • Save jonas-johansson/58899378b894ae69bff247385e1591be to your computer and use it in GitHub Desktop.
Save jonas-johansson/58899378b894ae69bff247385e1591be to your computer and use it in GitHub Desktop.
Git pre-commit hook that checks if there are any conflict markers present in any file.
#! /bin/sh
# Check to see if there are any conflict markers still present in a file. If so, exit 1 to prevent commit.
CONFLICT_MARKERS='<<<<<<<|=======|>>>>>>>'
CHECK=$(git diff --staged | grep "^+" | grep -Ei "$CONFLICT_MARKERS" -c)
if [ "$CHECK" -gt 0 ]
then
echo "ERROR: Conflict markers are still present in a file. Talk to a developer. Detected by a custom .git/hooks/pre-commit file."
git diff --name-only -G"$CONFLICT_MARKERS"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment