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

'git checkout -p' is a bit confusing...

From
John Szakmeister <john@szakmeister.net>
Date
May 9, 2011, 10:05 UTC
Message-ID
<BANLkTik+VbJZKc1Xwb-3p3HPW-zxanc7HQ@mail.gmail.com>

I noticed this a little while back, but thought it may have been my own misunderstanding. I wanted to selectively revert part of a file, so I used 'git checkout -p filename'. Then I needed to edit the hunk, and got something like this:

    # Manual hunk edit mode -- see bottom for a quick guide
    @@ -236,6 +236,12 @@ int run_add_interactive(const char *revision,
const char *patch_mode,
            }
            args[ac] = NULL;
    +        for (i=0; i < ac; i++)
    +          {
    +            fprintf(stderr, "%s ", args[i]);
    +          }
    +        fprintf(stderr, "\n");
    +
    # ---
    # To remove '+' lines, make them ' ' lines (context).
    # To remove '-' lines, delete them.
    # Lines starting with # will be removed.
    #
    # If the patch applies cleanly, the edited hunk will immediately be
    # marked for discarding. If it does not apply cleanly, you will be given
    # an opportunity to edit again. If all lines of the hunk are removed,
    # then the edit is aborted and the hunk is left unchanged.

Since the diff was showing me the forward direction (from the base to modified working tree), I expected that when I left the +'s in there, that it was going to leave my hunk. Unfortunately, it discarded my hunk. I can see the text at the bottom, and now it makes sense, but I wonder if there's a way to make it so that you can edit the patch to look the way you want, and keep those bits (in much the same way as 'git add -p' works)?

I hope that makes sense. :-)
Thank you!
-John
Next: Jeff King
Message 1 of 2 in “'git checkout -p' is a bit confusing...”
  1. John SzakmeisterMay 9, 2011
  2. Jeff KingMay 9, 2011

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.