Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mreishus
Created September 2, 2011 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mreishus/1189702 to your computer and use it in GitHub Desktop.
Save mreishus/1189702 to your computer and use it in GitHub Desktop.
git pre-commit for detecting conflicts
#!/bin/bash
#This goes in .git/hooks/pre-commit
git diff --cached --name-status | while read st file; do
# skip deleted files
if [ "$st" == 'D' ]; then continue; fi
if grep -q "^>>>>" "$file"; then
echo "Conflict detected in $file, aborting commit."
exit 1
fi
if grep -q "^====" "$file"; then
echo "Conflict detected in $file, aborting commit."
exit 1
fi
if grep -q "^<<<<" "$file"; then
echo "Conflict detected in $file, aborting commit."
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment