I use Git Gui, and very infrequently when I try to stage selected lines, I get an error message box:
Failed to stage selected line. error: patch failed: Foo/Bar.json:103 error: Foo/Bar.json: patch does not apply
Staging the entire file works, however.
Does anyone have any idea what might be causing this error? Has anyone else encountered it when using Git Gui?
First, make sure to use a recent Git (latest 2.23) minimal.
As I explain in "Why does git stash -p
sometimes fail?", git stash
(called by git-gui) has had a series of improvement since Git 2.17 (Q2 2018).
This happens for me any time I try to split a hunk into smaller hunks that are too close together (less than 3 lines between changes).
The short explanation is that the patch has context lines in it that conflict with your local changes.
See more at "Git stash apply did not return working directory?".
Playing with the diff.context
could help, minimizing the hunk context footprint.