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

RFE: Discard hunks during `git add -p`

From
Jan Engelhardt <jengelh@inai.de>
Date
Nov 2, 2016, 13:46 UTC
Message-ID
<alpine.LSU.2.20.1611021435280.21207@nerf40.vanv.qr>

Current version: 2.10.2 Example workflow:

* I would do a global substitution across a source tree, e.g. `perl -i 
  -pe 's{OLD_FOO\(x\)}{NEW_BAR(x, 0)}' *.c`
* Using `git add -p`, I would verify each of the substitutions that they 
  make sense in their respective locations, and, based on that,
  answer "y" or "n" to the interactive prompting to stage good hunks.
* When done with add-p, I would commit the so-staged hunks,
  and then use `git reset --hard` to discard all changes that were 
  not acknowledged during add-p.

Being able to discard hunks (reset working copy to index contents) during add-p would alleviate the (quite broad) hard reset.

Similar approach:
* global substitution
* Using `git add -p`, some hunks may warrant some more editing, doable 
  with the "e" command. The index would be updated with the extra
  change, but the working copy be left as-is.
* When rerunning `git add -p` in such a state, a difference is shown 
  again for such edited spots, which I would like to discard (bring 
  the working copy into sync with index).
Next: Konstantin Khomoutov
Message 1 of 4 in “RFE: Discard hunks during `git add -p`”
  1. Jan EngelhardtNov 2, 2016
  2. Konstantin KhomoutovNov 2, 2016
  3. Jeff KingNov 2, 2016
  4. Jeff KingNov 2, 2016

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.