* How to remove a specific hunk @ 2007-10-26 15:10 Pascal Obry 2007-10-26 15:28 ` Andreas Ericsson 2007-10-26 19:20 ` Alex Riesen 0 siblings, 2 replies; 15+ messages in thread From: Pascal Obry @ 2007-10-26 15:10 UTC (permalink / raw) To: git 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 ? Thanks, Pascal. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-26 15:10 How to remove a specific hunk Pascal Obry @ 2007-10-26 15:28 ` Andreas Ericsson 2007-10-26 15:38 ` Pascal Obry 2007-10-26 16:42 ` Jeff King 2007-10-26 19:20 ` Alex Riesen 1 sibling, 2 replies; 15+ messages in thread From: Andreas Ericsson @ 2007-10-26 15:28 UTC (permalink / raw) To: Pascal Obry; +Cc: git Pascal Obry wrote: > 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 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-26 15:28 ` Andreas Ericsson @ 2007-10-26 15:38 ` Pascal Obry 2007-10-26 17:03 ` Benoit SIGOURE 2007-10-26 21:59 ` Olivier Ramonat 2007-10-26 16:42 ` Jeff King 1 sibling, 2 replies; 15+ messages in thread From: Pascal Obry @ 2007-10-26 15:38 UTC (permalink / raw) To: Andreas Ericsson; +Cc: git Andreas, > 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 Thanks, this will clearly work. I was expecting something more integrated like a "git reset --interactive" or something like that :) Pascal. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-26 15:38 ` Pascal Obry @ 2007-10-26 17:03 ` Benoit SIGOURE 2007-10-26 18:19 ` Johannes Schindelin 2007-10-26 21:59 ` Olivier Ramonat 1 sibling, 1 reply; 15+ messages in thread From: Benoit SIGOURE @ 2007-10-26 17:03 UTC (permalink / raw) To: Pascal Obry; +Cc: git list [-- Attachment #1: Type: text/plain, Size: 595 bytes --] On Oct 26, 2007, at 5:38 PM, Pascal Obry wrote: > Andreas, > >> 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 > > Thanks, this will clearly work. I was expecting something more > integrated like a "git reset --interactive" or something like that :) That'd be great! :) -- Benoit Sigoure aka Tsuna EPITA Research and Development Laboratory [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 186 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-26 17:03 ` Benoit SIGOURE @ 2007-10-26 18:19 ` Johannes Schindelin 0 siblings, 0 replies; 15+ messages in thread From: Johannes Schindelin @ 2007-10-26 18:19 UTC (permalink / raw) To: Benoit SIGOURE; +Cc: Pascal Obry, git list Hi, On Fri, 26 Oct 2007, Benoit SIGOURE wrote: > On Oct 26, 2007, at 5:38 PM, Pascal Obry wrote: > > > Andreas, > > > > > 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 > > > > Thanks, this will clearly work. I was expecting something more > > integrated like a "git reset --interactive" or something like that :) > > That'd be great! :) I skipped over the beginnings of this thread because of time constraints, but would "git reset HEAD^ && git add -i" not helped you? git add -i allows you to stage hunks, so by just _not_ staging _that_ hunk but everything else, should have worked for you, right? There's also git-gui which does all that graphically for you (remember the right mouse button). Ciao, Dscho ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-26 15:38 ` Pascal Obry 2007-10-26 17:03 ` Benoit SIGOURE @ 2007-10-26 21:59 ` Olivier Ramonat 1 sibling, 0 replies; 15+ messages in thread From: Olivier Ramonat @ 2007-10-26 21:59 UTC (permalink / raw) To: git Pascal, Pascal Obry <pascal.obry@wanadoo.fr> writes: > Andreas, > >> 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 > > Thanks, this will clearly work. I was expecting something more > integrated like a "git reset --interactive" or something like that :) A solution could be : git add -i --> Add the two "good" hunks git checkout-index file_with_bad_hunk --> Remove the "bad" hunk by getting the staged version And then git reset HEAD file_with_bad_hunk if you want to unstage it. Olivier ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-26 15:28 ` Andreas Ericsson 2007-10-26 15:38 ` Pascal Obry @ 2007-10-26 16:42 ` Jeff King 2007-10-26 16:49 ` Jeff King 1 sibling, 1 reply; 15+ messages in thread From: Jeff King @ 2007-10-26 16:42 UTC (permalink / raw) To: Andreas Ericsson; +Cc: Pascal Obry, git On Fri, Oct 26, 2007 at 05:28:42PM +0200, Andreas Ericsson wrote: > 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 That has the side effect of changing the index state. My preferred method would be to just excise the hunk from the diff using an editor (and this actually has nothing to do with git; you could be using diff/patch): git-diff file >patch # remove every hunk except what you want to cut out $EDITOR patch git-apply -R patch -Peff ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-26 16:42 ` Jeff King @ 2007-10-26 16:49 ` Jeff King 2007-10-29 7:03 ` Miles Bader 0 siblings, 1 reply; 15+ messages in thread From: Jeff King @ 2007-10-26 16:49 UTC (permalink / raw) To: Andreas Ericsson; +Cc: Pascal Obry, git On Fri, Oct 26, 2007 at 12:42:08PM -0400, Jeff King wrote: > That has the side effect of changing the index state. My preferred > method would be to just excise the hunk from the diff using an editor > (and this actually has nothing to do with git; you could be using > diff/patch): > > git-diff file >patch > # remove every hunk except what you want to cut out > $EDITOR patch > git-apply -R patch BTW, since this is inherently a non-git operation, there are other tools that some may find friendlier than an editor. Kompare will let you unapply differences, for example, and I would be shocked if emacs didn't have some tool for this. -Peff ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-26 16:49 ` Jeff King @ 2007-10-29 7:03 ` Miles Bader 0 siblings, 0 replies; 15+ messages in thread From: Miles Bader @ 2007-10-29 7:03 UTC (permalink / raw) To: Jeff King; +Cc: Andreas Ericsson, Pascal Obry, git Jeff King <peff@peff.net> writes: > BTW, since this is inherently a non-git operation, there are other tools > that some may find friendlier than an editor. Kompare will let you > unapply differences, for example, and I would be shocked if emacs didn't > have some tool for this. M-x diff-mode <move to bad hunk> C-u C-c C-a -Miles -- Next to fried food, the South has suffered most from oratory. -- Walter Hines Page ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-26 15:10 How to remove a specific hunk Pascal Obry 2007-10-26 15:28 ` Andreas Ericsson @ 2007-10-26 19:20 ` Alex Riesen 2007-10-31 10:10 ` Benoit SIGOURE 1 sibling, 1 reply; 15+ messages in thread From: Alex Riesen @ 2007-10-26 19:20 UTC (permalink / raw) To: Pascal Obry; +Cc: git Pascal Obry, Fri, Oct 26, 2007 17:10:38 +0200: > > 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 ? Take a look at git-gui. Try right-clicking in the diff pane at the bottom. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-26 19:20 ` Alex Riesen @ 2007-10-31 10:10 ` Benoit SIGOURE 2007-10-31 11:06 ` Johannes Schindelin 0 siblings, 1 reply; 15+ messages in thread From: Benoit SIGOURE @ 2007-10-31 10:10 UTC (permalink / raw) To: Alex Riesen; +Cc: git list [-- Attachment #1: Type: text/plain, Size: 747 bytes --] On Oct 26, 2007, at 9:20 PM, Alex Riesen wrote: > Pascal Obry, Fri, Oct 26, 2007 17:10:38 +0200: >> >> 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 ? > > Take a look at git-gui. Try right-clicking in the diff pane at the > bottom. This only allows you to stage a given hunk, not to remove one. Right now I'm in a situation where I need to remove a specific hunk to compile and it's sad that git-gui doesn't provide an option so that you can right-click -> revert hunk. -- Benoit Sigoure aka Tsuna EPITA Research and Development Laboratory [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 186 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-31 10:10 ` Benoit SIGOURE @ 2007-10-31 11:06 ` Johannes Schindelin 2007-10-31 11:56 ` Florian Weimer 2007-10-31 12:00 ` Peter Baumann 0 siblings, 2 replies; 15+ messages in thread From: Johannes Schindelin @ 2007-10-31 11:06 UTC (permalink / raw) To: Benoit SIGOURE; +Cc: Alex Riesen, git list Hi, On Wed, 31 Oct 2007, Benoit SIGOURE wrote: > On Oct 26, 2007, at 9:20 PM, Alex Riesen wrote: > > > Pascal Obry, Fri, Oct 26, 2007 17:10:38 +0200: > > > > > > 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 ? > > > > Take a look at git-gui. Try right-clicking in the diff pane at the > > bottom. > > This only allows you to stage a given hunk, not to remove one. Right > now I'm in a situation where I need to remove a specific hunk to compile > and it's sad that git-gui doesn't provide an option so that you can > right-click -> revert hunk. You have seen that there are two different file lists, "staged changes" and "unstaged changes", right? AFAIK if you click on the file in "staged changes", you can find the staged hunk and then remove it from the staged area. "Revert hunk" would not make any sense, since the hunk disappears once you staged/unstaged it. Ciao, Dscho ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-31 11:06 ` Johannes Schindelin @ 2007-10-31 11:56 ` Florian Weimer 2007-10-31 12:24 ` Pascal Obry 2007-10-31 12:00 ` Peter Baumann 1 sibling, 1 reply; 15+ messages in thread From: Florian Weimer @ 2007-10-31 11:56 UTC (permalink / raw) To: Johannes Schindelin; +Cc: Benoit SIGOURE, Alex Riesen, git list * Johannes Schindelin: > You have seen that there are two different file lists, "staged > changes" and "unstaged changes", right? AFAIK if you click on the > file in "staged changes", you can find the staged hunk and then > remove it from the staged area. > > "Revert hunk" would not make any sense, since the hunk disappears > once you staged/unstaged it. I think Benoit wants to remove it from the working copy (and, presumably, the index too). "Revert hunk" and "Move hunk to stash" might indeed be useful additions to citool. -- Florian Weimer <fweimer@bfk.de> BFK edv-consulting GmbH http://www.bfk.de/ Kriegsstraße 100 tel: +49-721-96201-1 D-76133 Karlsruhe fax: +49-721-96201-99 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-31 11:56 ` Florian Weimer @ 2007-10-31 12:24 ` Pascal Obry 0 siblings, 0 replies; 15+ messages in thread From: Pascal Obry @ 2007-10-31 12:24 UTC (permalink / raw) To: Florian Weimer; +Cc: Johannes Schindelin, Benoit SIGOURE, Alex Riesen, git list Florian Weimer a écrit : > I think Benoit wants to remove it from the working copy (and, > presumably, the index too). "Revert hunk" and "Move hunk to stash" > might indeed be useful additions to citool. That was not Benoit but me who asked this question. I want indeed the hunk to be reverted/removed on the working copy. I had many answers to do this but I still think a "git reset --interactive" with the possibility to revert some hunks would be easier. Pascal. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: How to remove a specific hunk 2007-10-31 11:06 ` Johannes Schindelin 2007-10-31 11:56 ` Florian Weimer @ 2007-10-31 12:00 ` Peter Baumann 1 sibling, 0 replies; 15+ messages in thread From: Peter Baumann @ 2007-10-31 12:00 UTC (permalink / raw) To: Johannes Schindelin Cc: Benoit SIGOURE, Alex Riesen, Shawn O. Pearce, git list spearce Cc'ed, because this seems like a nice feature to add to git-gui In no way should this imply that YOU have to implement this! On Wed, Oct 31, 2007 at 11:06:18AM +0000, Johannes Schindelin wrote: > Hi, > > On Wed, 31 Oct 2007, Benoit SIGOURE wrote: > > > On Oct 26, 2007, at 9:20 PM, Alex Riesen wrote: > > > > > Pascal Obry, Fri, Oct 26, 2007 17:10:38 +0200: > > > > > > > > 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 ? > > > > > > Take a look at git-gui. Try right-clicking in the diff pane at the > > > bottom. > > > > This only allows you to stage a given hunk, not to remove one. Right > > now I'm in a situation where I need to remove a specific hunk to compile > > and it's sad that git-gui doesn't provide an option so that you can > > right-click -> revert hunk. > > You have seen that there are two different file lists, "staged changes" > and "unstaged changes", right? AFAIK if you click on the file in "staged > changes", you can find the staged hunk and then remove it from the staged > area. > > "Revert hunk" would not make any sense, since the hunk disappears once you > staged/unstaged it. > On the other hand, something like this would allow you to remove bogus hunks like debug statements you want to lose, because you tested it and all works now. Now you first have to stage all the things you want to keep, and then select "Commit->Revert Changes" in the menu to remove a hunk forever which is a little clumsy if you have many hunks and just want to remove one of them. Seems like a nice feature to add to git gui if you throw in an extra Yes-No question for the user IFF he realy wants to remove the hunk forever. -Peter ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2007-10-31 12:25 UTC | newest] Thread overview: 15+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2007-10-26 15:10 How to remove a specific hunk Pascal Obry 2007-10-26 15:28 ` Andreas Ericsson 2007-10-26 15:38 ` Pascal Obry 2007-10-26 17:03 ` Benoit SIGOURE 2007-10-26 18:19 ` Johannes Schindelin 2007-10-26 21:59 ` Olivier Ramonat 2007-10-26 16:42 ` Jeff King 2007-10-26 16:49 ` Jeff King 2007-10-29 7:03 ` Miles Bader 2007-10-26 19:20 ` Alex Riesen 2007-10-31 10:10 ` Benoit SIGOURE 2007-10-31 11:06 ` Johannes Schindelin 2007-10-31 11:56 ` Florian Weimer 2007-10-31 12:24 ` Pascal Obry 2007-10-31 12:00 ` Peter Baumann
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).