title: git commit trigger to block byte order mark
body: <p>I'm on Windows and sometimes edit files with Notepad, which likes to put a BOM at the start of the file (EF BB BF). It's easy overlook this in the diff and commit to Git a Python file with such a BOM, which I've found will not work on Mac.</p>
  
  <p>I want to create a commit trigger that removes the BOM before committing. Or at least rejects the commit.</p>
  
  <p>The best I've come up with is the script below which I put in 'pre-commit'. It removes any BOM but only after the commit, so then I have to make a second commit.</p>
  
  <pre><code>#!/bin/sh
  git diff --cached --diff-filter=ACMR --name-only -z *.py | xargs -0 -n 1 sh -c '
      for FILE; do
          sed -b -i -e "1s/^\xEF\xBB\xBF//" "$FILE"
      done
  ' sh
  </code></pre>
  
  <p>I tried to use commands and 'q' like this so the exit code would be 1 if it matched, but it doesn't work. </p>
  
  <pre><code>#!/bin/sh
  git diff --cached --diff-filter=ACMR --name-only -z *.py | xargs -0 -n 1 sh -c '
      for FILE; do
          sed -b -i -e "1 /^\xEF\xBB\xBF/ {s/^\xEF\xBB\xBF//;q1};q0" "$FILE"
      done
  ' sh
  </code></pre>
  
  <p>Can someone help fix it?</p>