Interview Prep/Git & GitHub/Config, Line Endings, Files and Platform Quirks

`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.

All Git & GitHub questions Roadmap: Git & GitHub

More on Config, Line Endings, Files and Platform Quirks