git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git add -p breaks after split on change at the top of the file

From
Simon Ruderich <simon@ruderich.org>
Date
Aug 16, 2017, 20:25 UTC
Message-ID
<20170816202442.aumzwa443spqgyul@ruderich.org>
Hello,
The following session reproduces the issue with Git 2.14.1:
    $ git init test
    $ cd test
    $ echo x >file
    $ git add file
    $ git commit -m commit
    $ printf 'a\nb\nx\nc\n' >file
    $ git add -p
    diff --git a/file b/file
    index 587be6b..74a69a0 100644
    --- a/file
    +++ b/file
    @@ -1 +1,4 @@
    +a
    +b
     x
    +c
    Stage this hunk [y,n,q,a,d,/,s,e,?]? <-- press s
    Split into 2 hunks.
    @@ -1 +1,3 @@
    +a
    +b
     x
    Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? <-- press e
    Now delete the line "+a" in your editor and save.
    error: patch failed: file:1
    error: file: patch does not apply

I expected git add -p to stage this change without error. It works fine without splitting the hunk (by deleting the first and last + line in the diff).

Regards Simon

-- 
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9
Next: Jeff King
Message 1 of 8 in “git add -p breaks after split on change at the top of the file”
  1. Simon RuderichAug 16, 2017
  2. Jeff KingAug 17, 2017
  3. Jeff KingAug 17, 2017
  4. Jeff KingAug 17, 2017
  5. Junio C HamanoAug 17, 2017
  6. Jeff KingAug 20, 2017
  7. Junio C HamanoAug 20, 2017
  8. Junio C HamanoAug 17, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.