0

I am trying to edit a certain hunk with a git: I use git add -p, then press s and then e. I make no changes (initially I tried to), save the file and it says that hunk does not apply.

Easy example:

  1. Create a file with the following content:

    aaa
    bbb
    ccc
    
  2. Commit it

  3. Add changes (three lines on the top and one line before the last line), so the file looks like

    111
    222
    333
    aaa
    bbb
    444
    ccc
    
  4. Run git add -p

  5. Press s to split

  6. Press e to edit. Edit nothing (really nothing)

  7. Save file with no changes

  8. It does not apply.

  9. ???

Any ideas..?

Ngoral
  • 4,215
  • 2
  • 20
  • 37
  • I bet it's to do with the line numbers at the top of the patch. – evolutionxbox Sep 12 '18 at 21:38
  • Like this `@@ -4,9 +4,12 @@`. https://stackoverflow.com/questions/987372/what-is-the-format-of-a-patch-file – evolutionxbox Sep 12 '18 at 21:38
  • @evolutionxbox Unfortunately, no. I know what they mean and usually is able to fix them so the hunk applies. I tried anything I can think of in this case and it didn't work out. However, those numbers are `@@ -1 +1,5 @@` which looks kind of strange. And it definetely is something about moving the very first line down. If I leave it, this works just fine. – Ngoral Sep 12 '18 at 21:47
  • Step 6 says "edit". What did you do? – evolutionxbox Sep 12 '18 at 21:49
  • @evolutionxbox NOTHING =) You can do nothing and it won't apply. You can easily reproduce it. Some friendв of mine and colleagues confirmed several issue on this example – Ngoral Sep 12 '18 at 21:53
  • The standard advice is: don't do that. If you want to split the hunk, don't edit it. Instead, edit the hunk and perform the split while editing. It's slightly more painful, but gets around the problem. – William Pursell Sep 12 '18 at 22:01
  • 1
    http://git.661346.n2.nabble.com/git-add-patch-bug-with-split-edit-td2171634.html – William Pursell Sep 12 '18 at 22:02
  • https://stackoverflow.com/questions/3268596/git-add-interactive-your-edited-hunk-does-not-apply/ – William Pursell Sep 12 '18 at 22:05
  • It's a bug in Git. See William Pursell's first link (to nabble.com) above. – torek Sep 12 '18 at 22:09
  • @WilliamPursell Thank you. For sure, there are better ways to do it, but, however, I faced this issue and became interested in the reasons. It is a bug but there was no any attention paid to it (according to the link you sent). Also, I read the question you send and tried to play along with the numbers like you offered in your answer there, but I didn't manage to find the right ones yet. – Ngoral Sep 12 '18 at 22:24

0 Answers0