4

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

enter image description here

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?

sashoalm
  • 75,001
  • 122
  • 434
  • 781

3 Answers3

2

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

In my case, it was because I had enabled -w as a diff parameter. Removing it fixed the issue.

enter image description here

sashoalm
  • 75,001
  • 122
  • 434
  • 781
0

I could add the lines when I reduce the 'context lines' to one in the Gui-Options (Menu Edit). This requires restarting the GUI. You can also change manually the value to zero.

enter image description here

SebastianRV
  • 25
  • 1
  • 7