`git apply fix.patch` fails with `error: patch failed: src/app.js:12` and `error: src/app.js: patch does not apply`.
IntermediateTroubleshootingConfig, Line Endings, Files and Platform Quirks
Answer
Likely causes → The file changed since the patch was created (context lines no longer match), whitespace or line endings differ, or the path prefix level is wrong.
Diagnose →
git apply --check -v fix.patch
head -20 fix.patch # check a/ b/ prefixes and the base index line
Fix → Try, in order:
git apply --3way fix.patch # uses blob IDs in the patch to do a real merge
git apply --ignore-whitespace fix.patch
git apply -p0 fix.patch # when paths have no a/ b/ prefix
git apply --reject fix.patch # applies what fits, writes *.rej for the rest
Prevent → Share changes as branches or git format-patch output (with full index lines) rather than plain diff output.
More on Config, Line Endings, Files and Platform Quirks
`warning: in the working copy of 'app.sh', LF will be replaced by CRLF the next time Git touches it`Beginner`git diff` shows `old mode 100755` / `new mode 100644` for hundreds of files with no content change.BeginnerCloning on Windows fails with `error: unable to create file src/very/deep/.../component.test.ts: Filename too long`.BeginnerYou renamed `header.tsx` to `Header.tsx` on macOS. Locally everything builds, but Linux CI fails with `Module not found: Can't resolve './components/Header'`.IntermediateCheckout on Windows fails with `error: invalid path 'logs/2024-01-01T10:00:00.log'` (or `'docs/aux.md'`) and `fatal: unable to checkout working tree`.IntermediateClone prints `warning: the following paths have collided (e.g. case-sensitive paths on a case-insensitive filesystem) and only one from the same colliding group is in the working tree:`Intermediate