{"thread":{"id":"10476","subject":"How to remove a specific hunk","startedAt":"2007-10-26T15:10:38Z","lastAt":"2007-10-31T12:24:58Z","messageCount":15,"participants":["Pascal Obry","Andreas Ericsson","Jeff King","Benoit SIGOURE","Johannes Schindelin","Alex Riesen","Olivier Ramonat","Miles Bader","Florian Weimer","Peter Baumann"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"57279","messageId":"4722036E.5030204@wanadoo.fr","threadId":"10476","inReplyTo":null,"subject":"How to remove a specific hunk","fromName":"Pascal Obry","fromEmail":"pascal.obry@wanadoo.fr","sentAt":"2007-10-26T15:10:38Z","receivedAt":"2007-10-26T15:10:38Z","isPatch":false,"sender":{"key":"pascal@obry.net","avatar":"https://avatars.githubusercontent.com/u/467069?v=4"},"body":"\nHello,\n\nI'm very new to Git... but start to love it :)\n\nBefore committing sometimes I want to remove a specific hunk. Say in\nfile a.txt I have in the diff 3 hunks, I want to revert/delete/remove\nthe second one. Is there a way to do that ?\n\nI understand that I can git add interactive and select the hook I want\nto commit, but this is not fully equivalent. I'm not yet ready to commit\nI just want to undo a specific change and test the code without it...\n\nAny idea ?\n\nThanks,\nPascal.\n\n-- \n\n--|------------------------------------------------------\n--| Pascal Obry                           Team-Ada Member\n--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE\n--|------------------------------------------------------\n--|              http://www.obry.net\n--| \"The best way to travel is by means of imagination\"\n--|\n--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595\n"},{"id":"57282","messageId":"472207AA.8030100@op5.se","threadId":"10476","inReplyTo":"4722036E.5030204@wanadoo.fr","subject":"Re: How to remove a specific hunk","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2007-10-26T15:28:42Z","receivedAt":"2007-10-26T15:28:42Z","isPatch":false,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Pascal Obry wrote:\n> Hello,\n> \n> I'm very new to Git... but start to love it :)\n> \n> Before committing sometimes I want to remove a specific hunk. Say in\n> file a.txt I have in the diff 3 hunks, I want to revert/delete/remove\n> the second one. Is there a way to do that ?\n> \n> I understand that I can git add interactive and select the hook I want\n> to commit, but this is not fully equivalent. I'm not yet ready to commit\n> I just want to undo a specific change and test the code without it...\n> \n> Any idea ?\n> \n\nOnce you've added the other two hunks, they'll no longer show up in\ngit-diff, so you can do something like this:\n\n$ git-add -i; # add the other two hunks to commit\n$ git-diff > middle-hunk.patch\n$ git-apply -R middle-hunk.patch\ntest, test, test\n$ git-apply middle-hunk.patch\n\nCompletely untested, so take a copy before you try it.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"},{"id":"57284","messageId":"47220A05.4040705@wanadoo.fr","threadId":"10476","inReplyTo":"472207AA.8030100@op5.se","subject":"Re: How to remove a specific hunk","fromName":"Pascal Obry","fromEmail":"pascal.obry@wanadoo.fr","sentAt":"2007-10-26T15:38:45Z","receivedAt":"2007-10-26T15:38:45Z","isPatch":false,"sender":{"key":"pascal@obry.net","avatar":"https://avatars.githubusercontent.com/u/467069?v=4"},"body":"Andreas,\n\n> Once you've added the other two hunks, they'll no longer show up in\n> git-diff, so you can do something like this:\n> \n> $ git-add -i; # add the other two hunks to commit\n> $ git-diff > middle-hunk.patch\n> $ git-apply -R middle-hunk.patch\n> test, test, test\n> $ git-apply middle-hunk.patch\n\nThanks, this will clearly work. I was expecting something more\nintegrated like a \"git reset --interactive\" or something like that :)\n\nPascal.\n\n-- \n\n--|------------------------------------------------------\n--| Pascal Obry                           Team-Ada Member\n--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE\n--|------------------------------------------------------\n--|              http://www.obry.net\n--| \"The best way to travel is by means of imagination\"\n--|\n--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595\n"},{"id":"57290","messageId":"20071026164207.GB19673@coredump.intra.peff.net","threadId":"10476","inReplyTo":"472207AA.8030100@op5.se","subject":"Re: How to remove a specific hunk","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-10-26T16:42:08Z","receivedAt":"2007-10-26T16:42:08Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Oct 26, 2007 at 05:28:42PM +0200, Andreas Ericsson wrote:\n\n> Once you've added the other two hunks, they'll no longer show up in\n> git-diff, so you can do something like this:\n>\n> $ git-add -i; # add the other two hunks to commit\n> $ git-diff > middle-hunk.patch\n> $ git-apply -R middle-hunk.patch\n> test, test, test\n> $ git-apply middle-hunk.patch\n\nThat has the side effect of changing the index state. My preferred\nmethod would be to just excise the hunk from the diff using an editor\n(and this actually has nothing to do with git; you could be using\ndiff/patch):\n\ngit-diff file >patch\n# remove every hunk except what you want to cut out\n$EDITOR patch\ngit-apply -R patch\n\n-Peff\n"},{"id":"57293","messageId":"20071026164926.GA21160@coredump.intra.peff.net","threadId":"10476","inReplyTo":"20071026164207.GB19673@coredump.intra.peff.net","subject":"Re: How to remove a specific hunk","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-10-26T16:49:26Z","receivedAt":"2007-10-26T16:49:26Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Oct 26, 2007 at 12:42:08PM -0400, Jeff King wrote:\n\n> That has the side effect of changing the index state. My preferred\n> method would be to just excise the hunk from the diff using an editor\n> (and this actually has nothing to do with git; you could be using\n> diff/patch):\n> \n> git-diff file >patch\n> # remove every hunk except what you want to cut out\n> $EDITOR patch\n> git-apply -R patch\n\nBTW, since this is inherently a non-git operation, there are other tools\nthat some may find friendlier than an editor. Kompare will let you\nunapply differences, for example, and I would be shocked if emacs didn't\nhave some tool for this.\n\n-Peff\n"},{"id":"57296","messageId":"2669F76D-6FF2-4CCF-9337-639D84EE65E8@lrde.epita.fr","threadId":"10476","inReplyTo":"47220A05.4040705@wanadoo.fr","subject":"Re: How to remove a specific hunk","fromName":"Benoit SIGOURE","fromEmail":"tsuna@lrde.epita.fr","sentAt":"2007-10-26T17:03:49Z","receivedAt":"2007-10-26T17:03:49Z","isPatch":false,"sender":{"key":"tsunanet@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128281?v=4"},"body":"On Oct 26, 2007, at 5:38 PM, Pascal Obry wrote:\n\n> Andreas,\n>\n>> Once you've added the other two hunks, they'll no longer show up in\n>> git-diff, so you can do something like this:\n>>\n>> $ git-add -i; # add the other two hunks to commit\n>> $ git-diff > middle-hunk.patch\n>> $ git-apply -R middle-hunk.patch\n>> test, test, test\n>> $ git-apply middle-hunk.patch\n>\n> Thanks, this will clearly work. I was expecting something more\n> integrated like a \"git reset --interactive\" or something like that :)\n\nThat'd be great!  :)\n\n-- \nBenoit Sigoure aka Tsuna\nEPITA Research and Development Laboratory\n\n\n"},{"id":"57299","messageId":"Pine.LNX.4.64.0710261917270.4362@racer.site","threadId":"10476","inReplyTo":"2669F76D-6FF2-4CCF-9337-639D84EE65E8@lrde.epita.fr","subject":"Re: How to remove a specific hunk","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-10-26T18:19:32Z","receivedAt":"2007-10-26T18:19:32Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 26 Oct 2007, Benoit SIGOURE wrote:\n\n> On Oct 26, 2007, at 5:38 PM, Pascal Obry wrote:\n> \n> > Andreas,\n> > \n> > > Once you've added the other two hunks, they'll no longer show up in\n> > > git-diff, so you can do something like this:\n> > > \n> > > $ git-add -i; # add the other two hunks to commit\n> > > $ git-diff > middle-hunk.patch\n> > > $ git-apply -R middle-hunk.patch\n> > > test, test, test\n> > > $ git-apply middle-hunk.patch\n> > \n> > Thanks, this will clearly work. I was expecting something more\n> > integrated like a \"git reset --interactive\" or something like that :)\n> \n> That'd be great!  :)\n\nI skipped over the beginnings of this thread because of time constraints, \nbut would \"git reset HEAD^ && git add -i\" not helped you?  git add -i \nallows you to stage hunks, so by just _not_ staging _that_ hunk but \neverything else, should have worked for you, right?\n\nThere's also git-gui which does all that graphically for you (remember the \nright mouse button).\n\nCiao,\nDscho\n"},{"id":"57300","messageId":"20071026192034.GA3062@steel.home","threadId":"10476","inReplyTo":"4722036E.5030204@wanadoo.fr","subject":"Re: How to remove a specific hunk","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-10-26T19:20:34Z","receivedAt":"2007-10-26T19:20:34Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Pascal Obry, Fri, Oct 26, 2007 17:10:38 +0200:\n> \n> I'm very new to Git... but start to love it :)\n> \n> Before committing sometimes I want to remove a specific hunk. Say in\n> file a.txt I have in the diff 3 hunks, I want to revert/delete/remove\n> the second one. Is there a way to do that ?\n\nTake a look at git-gui. Try right-clicking in the diff pane at the\nbottom.\n"},{"id":"57311","messageId":"87prz1a65q.fsf@tah.ramonat.fr","threadId":"10476","inReplyTo":"47220A05.4040705@wanadoo.fr","subject":"Re: How to remove a specific hunk","fromName":"Olivier Ramonat","fromEmail":"olivier@ramonat.fr","sentAt":"2007-10-26T21:59:45Z","receivedAt":"2007-10-26T21:59:45Z","isPatch":false,"sender":{"key":"olivier@ramonat.fr","avatar":null},"body":"Pascal,\n\nPascal Obry <pascal.obry@wanadoo.fr> writes:\n> Andreas,\n>\n>> Once you've added the other two hunks, they'll no longer show up in\n>> git-diff, so you can do something like this:\n>> \n>> $ git-add -i; # add the other two hunks to commit\n>> $ git-diff > middle-hunk.patch\n>> $ git-apply -R middle-hunk.patch\n>> test, test, test\n>> $ git-apply middle-hunk.patch\n>\n> Thanks, this will clearly work. I was expecting something more\n> integrated like a \"git reset --interactive\" or something like that :)\n\nA solution could be :\n\ngit add -i \n--> Add the two \"good\" hunks\n\ngit checkout-index file_with_bad_hunk\n--> Remove the \"bad\" hunk by getting the staged version\n\nAnd then \ngit reset HEAD file_with_bad_hunk \nif you want to unstage it.\n\nOlivier\n"},{"id":"57470","messageId":"buor6jeo11g.fsf@dhapc248.dev.necel.com","threadId":"10476","inReplyTo":"20071026164926.GA21160@coredump.intra.peff.net","subject":"Re: How to remove a specific hunk","fromName":"Miles Bader","fromEmail":"miles.bader@necel.com","sentAt":"2007-10-29T07:03:23Z","receivedAt":"2007-10-29T07:03:23Z","isPatch":false,"sender":{"key":"miles.bader@necel.com","avatar":"https://gravatar.com/avatar/be062d4050eb88e04229cbdb60f803e1bd647923a015996c2439e76f23e336a7?d=mp&s=160"},"body":"Jeff King <peff@peff.net> writes:\n> BTW, since this is inherently a non-git operation, there are other tools\n> that some may find friendlier than an editor. Kompare will let you\n> unapply differences, for example, and I would be shocked if emacs didn't\n> have some tool for this.\n\nM-x diff-mode\n<move to bad hunk>\nC-u C-c C-a\n\n-Miles\n\n-- \nNext to fried food, the South has suffered most from oratory.\n  \t\t\t-- Walter Hines Page\n"},{"id":"57678","messageId":"13D08D3F-3647-4E20-AF80-8EC6FD14E66A@lrde.epita.fr","threadId":"10476","inReplyTo":"20071026192034.GA3062@steel.home","subject":"Re: How to remove a specific hunk","fromName":"Benoit SIGOURE","fromEmail":"tsuna@lrde.epita.fr","sentAt":"2007-10-31T10:10:34Z","receivedAt":"2007-10-31T10:10:34Z","isPatch":false,"sender":{"key":"tsunanet@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128281?v=4"},"body":"On Oct 26, 2007, at 9:20 PM, Alex Riesen wrote:\n\n> Pascal Obry, Fri, Oct 26, 2007 17:10:38 +0200:\n>>\n>> I'm very new to Git... but start to love it :)\n>>\n>> Before committing sometimes I want to remove a specific hunk. Say in\n>> file a.txt I have in the diff 3 hunks, I want to revert/delete/remove\n>> the second one. Is there a way to do that ?\n>\n> Take a look at git-gui. Try right-clicking in the diff pane at the\n> bottom.\n\nThis only allows you to stage a given hunk, not to remove one.  Right  \nnow I'm in a situation where I need to remove a specific hunk to  \ncompile and it's sad that git-gui doesn't provide an option so that  \nyou can right-click -> revert hunk.\n\n-- \nBenoit Sigoure aka Tsuna\nEPITA Research and Development Laboratory\n\n\n"},{"id":"57683","messageId":"Pine.LNX.4.64.0710311104450.4362@racer.site","threadId":"10476","inReplyTo":"13D08D3F-3647-4E20-AF80-8EC6FD14E66A@lrde.epita.fr","subject":"Re: How to remove a specific hunk","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-10-31T11:06:18Z","receivedAt":"2007-10-31T11:06:18Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 31 Oct 2007, Benoit SIGOURE wrote:\n\n> On Oct 26, 2007, at 9:20 PM, Alex Riesen wrote:\n> \n> > Pascal Obry, Fri, Oct 26, 2007 17:10:38 +0200:\n> > > \n> > > I'm very new to Git... but start to love it :)\n> > > \n> > > Before committing sometimes I want to remove a specific hunk. Say in\n> > > file a.txt I have in the diff 3 hunks, I want to revert/delete/remove\n> > > the second one. Is there a way to do that ?\n> > \n> > Take a look at git-gui. Try right-clicking in the diff pane at the\n> > bottom.\n> \n> This only allows you to stage a given hunk, not to remove one.  Right \n> now I'm in a situation where I need to remove a specific hunk to compile \n> and it's sad that git-gui doesn't provide an option so that you can \n> right-click -> revert hunk.\n\nYou have seen that there are two different file lists, \"staged changes\" \nand \"unstaged changes\", right?  AFAIK if you click on the file in \"staged \nchanges\", you can find the staged hunk and then remove it from the staged \narea.\n\n\"Revert hunk\" would not make any sense, since the hunk disappears once you \nstaged/unstaged it.\n\nCiao,\nDscho\n"},{"id":"57684","messageId":"82zlxzsdkf.fsf@mid.bfk.de","threadId":"10476","inReplyTo":"Pine.LNX.4.64.0710311104450.4362@racer.site","subject":"Re: How to remove a specific hunk","fromName":"Florian Weimer","fromEmail":"fweimer@bfk.de","sentAt":"2007-10-31T11:56:00Z","receivedAt":"2007-10-31T11:56:00Z","isPatch":false,"sender":{"key":"fweimer@bfk.de","avatar":null},"body":"* Johannes Schindelin:\n\n> You have seen that there are two different file lists, \"staged\n> changes\" and \"unstaged changes\", right?  AFAIK if you click on the\n> file in \"staged changes\", you can find the staged hunk and then\n> remove it from the staged area.\n>\n> \"Revert hunk\" would not make any sense, since the hunk disappears\n> once you staged/unstaged it.\n\nI think Benoit wants to remove it from the working copy (and,\npresumably, the index too).  \"Revert hunk\" and \"Move hunk to stash\"\nmight indeed be useful additions to citool.\n\n-- \nFlorian Weimer                <fweimer@bfk.de>\nBFK edv-consulting GmbH       http://www.bfk.de/\nKriegsstraße 100              tel: +49-721-96201-1\nD-76133 Karlsruhe             fax: +49-721-96201-99\n"},{"id":"57685","messageId":"20071031120011.GI4435@xp.machine.xx","threadId":"10476","inReplyTo":"Pine.LNX.4.64.0710311104450.4362@racer.site","subject":"Re: How to remove a specific hunk","fromName":"Peter Baumann","fromEmail":"waste.manager@gmx.de","sentAt":"2007-10-31T12:00:11Z","receivedAt":"2007-10-31T12:00:11Z","isPatch":false,"sender":{"key":"waste.manager@gmx.de","avatar":null},"body":"\nspearce Cc'ed, because this seems like a nice feature to add to git-gui\nIn no way should this imply that YOU have to implement this!\n\n\nOn Wed, Oct 31, 2007 at 11:06:18AM +0000, Johannes Schindelin wrote:\n> Hi,\n> \n> On Wed, 31 Oct 2007, Benoit SIGOURE wrote:\n> \n> > On Oct 26, 2007, at 9:20 PM, Alex Riesen wrote:\n> > \n> > > Pascal Obry, Fri, Oct 26, 2007 17:10:38 +0200:\n> > > > \n> > > > Before committing sometimes I want to remove a specific hunk. Say in\n> > > > file a.txt I have in the diff 3 hunks, I want to revert/delete/remove\n> > > > the second one. Is there a way to do that ?\n> > > \n> > > Take a look at git-gui. Try right-clicking in the diff pane at the\n> > > bottom.\n> > \n> > This only allows you to stage a given hunk, not to remove one.  Right \n> > now I'm in a situation where I need to remove a specific hunk to compile \n> > and it's sad that git-gui doesn't provide an option so that you can \n> > right-click -> revert hunk.\n> \n> You have seen that there are two different file lists, \"staged changes\" \n> and \"unstaged changes\", right?  AFAIK if you click on the file in \"staged \n> changes\", you can find the staged hunk and then remove it from the staged \n> area.\n> \n> \"Revert hunk\" would not make any sense, since the hunk disappears once you \n> staged/unstaged it.\n> \n\nOn the other hand, something like this would allow you to remove bogus\nhunks like debug statements you want to lose, because you tested it and\nall works now.\n\nNow you first have to stage all the things you want to keep, and then\nselect \"Commit->Revert Changes\" in the menu to remove a hunk forever which\nis a little clumsy if you have many hunks and just want to remove one of\nthem. Seems like a nice feature to add to git gui if you throw in an extra\nYes-No question for the user IFF he realy wants to remove the hunk forever.\n\n-Peter\n"},{"id":"57686","messageId":"4728741A.90503@obry.net","threadId":"10476","inReplyTo":"82zlxzsdkf.fsf@mid.bfk.de","subject":"Re: How to remove a specific hunk","fromName":"Pascal Obry","fromEmail":"pascal@obry.net","sentAt":"2007-10-31T12:24:58Z","receivedAt":"2007-10-31T12:24:58Z","isPatch":false,"sender":{"key":"pascal@obry.net","avatar":"https://avatars.githubusercontent.com/u/467069?v=4"},"body":"Florian Weimer a écrit :\n> I think Benoit wants to remove it from the working copy (and,\n> presumably, the index too).  \"Revert hunk\" and \"Move hunk to stash\"\n> might indeed be useful additions to citool.\n\nThat was not Benoit but me who asked this question. I want indeed the\nhunk to be reverted/removed on the working copy. I had many answers to\ndo this but I still think a \"git reset --interactive\" with the\npossibility to revert some hunks would be easier.\n\nPascal.\n\n-- \n\n--|------------------------------------------------------\n--| Pascal Obry                           Team-Ada Member\n--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE\n--|------------------------------------------------------\n--|              http://www.obry.net\n--| \"The best way to travel is by means of imagination\"\n--|\n--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595\n"}]}