4

I have this hunk, and I'd like to edit it so that the changes to uuid are ignored.

# Manual hunk edit mode -- see bottom for a quick guide.
@@ -43,4 +44,7 @@
        "date-fns": "^2.23.0",
-       "uuid": "^8.3.2"
+       "imask": "^6.1.0",
+       "uuid": "^8.3.2",
+       "validator": "^13.6.0",
+       "vest": "^3.2.5"
    }
 }
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.

My idea so far is to do the following which would mean the hunk header doesn't need to change (right?).

# Manual hunk edit mode -- see bottom for a quick guide.
@@ -43,4 +44,7 @@
        "date-fns": "^2.23.0",
        "uuid": "^8.3.2"
+       "imask": "^6.1.0",
+       "validator": "^13.6.0",
+       "vest": "^3.2.5"
    }
 }
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.

But still, after saving changes and quitting I get the following:

error: patch failed: package.json:43
error: package.json: patch does not apply

At this point, I'm confused and I'm not sure what to try. At first I thought it was the missing space because my VIM configuration replaces it with tabs, but manually adding the space doesn't fix it either (in the - line).

My only guess so far is that it's a problem with the header, but it should line up correctly right? I'm still adding 7 lines in both cases and the 4 stays the same.

I've reviewed similar questions but haven't found something tackling such problem.

I could try and use a GUI, but I'd like to avoid it if possible.

Any ideas? I'd appreciate it.

fillipvt
  • 556
  • 3
  • 14
  • "because my VIM configuration replaces it with tabs" probably deserves more investigation. I think silently changing white space is a bad default setting for a vimrc. – jthill Sep 06 '21 at 18:47
  • @jthill sorry, it's the other way around, it changes tabs to spaces – fillipvt Sep 06 '21 at 19:01
  • but yeah, I'll investigate more and see if there's anything there – fillipvt Sep 06 '21 at 19:01
  • What got me to comment was, I was looking at the patch edits thinking "there's nothing wrong there, why is this failing" and arrived at whitespace trouble before reading the end of your question. But I haven't done a whole lot of hunk editing so this is just me tossing my two bits in. – jthill Sep 06 '21 at 19:43
  • Note that there's never[1] any need to adjust the hunk headers here: the patch code uses `--recount` to get Git to ignore the header counts in the first place. But yes, the change you show *should* apply, so tabs-vs-spaces seems a likely culprit. [1: modulo bugs in the source code of course; but a bug around re-count is unlikely. Some versions of Git have a bug with add --patch whose details I have forgotten but it's not related to line counts.] – torek Sep 06 '21 at 20:37
  • FWIW : note that applying the patch you present in your question would lead to an invalid `package.json` file : there wouldn't be a `,` (a coma) after the `"uuid": "^8.3.2"` entry – LeGEC Sep 06 '21 at 20:53
  • Another user stumbled on a similar issue using `git add -p` : [Can't remove line from being added to staging area](https://stackoverflow.com/questions/62896307/cant-remove-line-from-being-added-to-staging-area/62897311#62897311) Did you have to `[s]plit` a hunk before choosing to edit that hunk around `"uuid"` ? – LeGEC Sep 06 '21 at 20:58
  • @LeGEC yes! I did had to split it first! – fillipvt Sep 07 '21 at 21:37

1 Answers1

2

It seems you fell on the same issue as this other user : if you split a hunk in git add -p, there is a bug that prevents applying "edit manually" a sub hunk.

The workaround is simple : put aside your current version of package.json, and edit that file to the version you want to commit.

Also worth noting : git gui offers a perfectly functional "stage this line" action -- when you right click on any line in the diff displayed in the right pane.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • The workaround works simple enough! Thanks! – fillipvt Sep 08 '21 at 14:34
  • 1
    Tried using `git gui` but I'm getting some obscure error with very few results on Google. `error: git-gui died of signal 11`. I'm unable to use it so far, in Arch Linux (Manjaro). – fillipvt Sep 08 '21 at 14:35