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

Re: How to remove a specific hunk

From
Andreas Ericsson <ae@op5.se>
Date
Oct 26, 2007, 15:28 UTC
Message-ID
<472207AA.8030100@op5.se>
In-Reply-To
<4722036E.5030204@wanadoo.fr>
Pascal Obry wrote:
Show 14 quoted lines
> Hello,
> 
> I'm very new to Git... but start to love it :)
> 
> Before committing sometimes I want to remove a specific hunk. Say in
> file a.txt I have in the diff 3 hunks, I want to revert/delete/remove
> the second one. Is there a way to do that ?
> 
> I understand that I can git add interactive and select the hook I want
> to commit, but this is not fully equivalent. I'm not yet ready to commit
> I just want to undo a specific change and test the code without it...
> 
> Any idea ?
> 

Once you've added the other two hunks, they'll no longer show up in git-diff, so you can do something like this:

$ git-add -i; # add the other two hunks to commit $ git-diff > middle-hunk.patch $ git-apply -R middle-hunk.patch test, test, test $ git-apply middle-hunk.patch

Completely untested, so take a copy before you try it.
-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Previous: Pascal ObryNext: Pascal Obry
Message 2 of 15 in “How to remove a specific hunk”
  1. Pascal ObryOct 26, 2007
  2. Andreas EricssonOct 26, 2007
  3. Pascal ObryOct 26, 2007
  4. Benoit SIGOUREOct 26, 2007
  5. Johannes SchindelinOct 26, 2007
  6. Olivier RamonatOct 26, 2007
  7. Jeff KingOct 26, 2007
  8. Jeff KingOct 26, 2007
  9. Miles BaderOct 29, 2007
  10. Alex RiesenOct 26, 2007
  11. Benoit SIGOUREOct 31, 2007
  12. Johannes SchindelinOct 31, 2007
  13. Florian WeimerOct 31, 2007
  14. Pascal ObryOct 31, 2007
  15. Peter BaumannOct 31, 2007

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.