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.

8
  • "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. Commented Sep 6, 2021 at 18:47
  • @jthill sorry, it's the other way around, it changes tabs to spaces Commented Sep 6, 2021 at 19:01
  • but yeah, I'll investigate more and see if there's anything there Commented Sep 6, 2021 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. Commented Sep 6, 2021 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.] Commented Sep 6, 2021 at 20:37

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

The workaround works simple enough! Thanks!
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).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.