Search code examples
gitpatchbyte-order-mark

My git apply patch fails because the target file has UTF8 BOM - how do I fix it?


As the title says, I am trying to apply a patch to a file and it fails because the file has the UTF8 BOM, but the patch does not mention it.

How can I resolve around it without removing the UTF8 BOM from the file?


Solution

  • The simplest solution is to remove it, perhaps temporarily (i.e., remove it, apply patch, put it back). Since git apply works by default on the work-tree contents, this should be easy enough and does not require making or deleting any commits.

    Note that a UTF-8 BOM is technically useless, because UTF-8 has no byte-order issue in the first place. (Some software might use it to imply that the file is UTF-8 encoded, though.)