Skip to content

Instantly share code, notes, and snippets.

@swape
Created April 11, 2017 21:00
Show Gist options
  • Save swape/8dc286fc067ed7c8180cddc5501110eb to your computer and use it in GitHub Desktop.
Save swape/8dc286fc067ed7c8180cddc5501110eb to your computer and use it in GitHub Desktop.
pre-commit script to prevent merge markers from being committed
#!/bin/sh
## pre-commit script to prevent merge markers from being committed.
## filename: .git/hooks/pre-commit
changed=$(git diff --cached --name-only)
if [[ -z "$changed" ]]
then
exit 0
fi
echo $changed | xargs egrep '[><]{7}' -H -I --line-number
## If the egrep command has any hits - echo a warning and exit with non-zero status.
if [ $? == 0 ]
then
echo "\n\nWARNING: You have merge markers in the above files, lines. Fix them before committing.\n\n"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment