Created
          June 23, 2025 09:02 
        
      - 
      
- 
        Save limpido/2fb7c7b713faf2e70678091836a0a925 to your computer and use it in GitHub Desktop. 
    git pre-commit hook to check whitespace errors
  
        
  
    
      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
    
  
  
    
  | 1 #!/usr/bin/bash | |
| 2 | |
| 3 if git rev-parse --verify HEAD >/dev/null 2>&1 | |
| 4 then | |
| 5 against=HEAD | |
| 6 else | |
| 7 echo "pre-commit: About to create the first commit..." | |
| 8 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 # magic commit ID for empty commit | |
| 9 fi | |
| 10 | |
| 11 if ! git diff-index --check --cached $against | |
| 12 then | |
| 13 echo "pre-commit: Aborting commit due to whitespace errors" | |
| 14 exit 1 | |
| 15 fi | |
| 16 | |
| 17 exit 0 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment