Created
September 2, 2011 19:51
-
-
Save mreishus/1189702 to your computer and use it in GitHub Desktop.
git pre-commit for detecting conflicts
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 | |
#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