{"thread":{"id":"16771","subject":"Is it possible to roll back unstaged changes while leaving the staged ones for the next commit?","startedAt":"2008-12-17T19:57:08Z","lastAt":"2008-12-18T12:24:11Z","messageCount":7,"participants":["Tim Visher","Junio C Hamano","Nanako Shiraishi"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"98169","messageId":"c115fd3c0812171157m3d180534gb5630fbcf39b2bbd@mail.gmail.com","threadId":"16771","inReplyTo":null,"subject":"Is it possible to roll back unstaged changes while leaving the staged ones for the next commit?","fromName":"Tim Visher","fromEmail":"tim.visher@gmail.com","sentAt":"2008-12-17T19:57:08Z","receivedAt":"2008-12-17T19:57:08Z","isPatch":false,"sender":{"key":"tim.visher@gmail.com","avatar":"https://gravatar.com/avatar/98307ce54bcac1a46b5d845827d5386e2a27895ff08790cdd3877ad527760575?d=mp&s=160"},"body":"Hello Everyone,\n\nI'm attempting to use `git add -i` to help me resolve the differences\nbetween two files in a way that makes sense (leaving class names, some\nlogic, but changing other things like white space, etc.).  I have all\nof the changes that I want to be committed staged now in the index.\nMy question is this: is it possible to revert the changes that I\nhaven't staged so that the file looks as if everything inside of it\nhas been staged because none of the stuff I didn't stage is there\nanymore.\n\nThanks in advance!\n\n-- \n\nIn Christ,\n\nTimmy V.\n\nhttp://burningones.com/\nhttp://five.sentenc.es/ - Spend less time on e-mail\n"},{"id":"98175","messageId":"7vy6yelf2m.fsf@gitster.siamese.dyndns.org","threadId":"16771","inReplyTo":"c115fd3c0812171157m3d180534gb5630fbcf39b2bbd@mail.gmail.com","subject":"Re: Is it possible to roll back unstaged changes while leaving the staged ones for the next commit?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-12-17T20:30:41Z","receivedAt":"2008-12-17T20:30:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Tim Visher\" <tim.visher@gmail.com> writes:\n\n> My question is this: is it possible to revert the changes that I\n> haven't staged so that the file looks as if everything inside of it\n> has been staged because none of the stuff I didn't stage is there\n> anymore.\n\nThe last part of the sentence after \"because\" does not parse for me at\nall, but I think you are after one of the following:\n\n (1) if you want to get rid of garbage changes in your work tree, you\n     would want \"git checkout $that_path\";\n\n (2) if you want to temporarily stash away further changes in your work\n     tree, because you would want to first test what is staged, commit it,\n     and then later continue to refine the changes stashed away thusly,\n     you would want \"git stash --keep-index\".\n"},{"id":"98199","messageId":"c115fd3c0812171448o3db6f4c1oc24e39f9a68ed1d3@mail.gmail.com","threadId":"16771","inReplyTo":"7vy6yelf2m.fsf@gitster.siamese.dyndns.org","subject":"Re: Is it possible to roll back unstaged changes while leaving the staged ones for the next commit?","fromName":"Tim Visher","fromEmail":"tim.visher@gmail.com","sentAt":"2008-12-17T22:48:50Z","receivedAt":"2008-12-17T22:48:50Z","isPatch":false,"sender":{"key":"tim.visher@gmail.com","avatar":"https://gravatar.com/avatar/98307ce54bcac1a46b5d845827d5386e2a27895ff08790cdd3877ad527760575?d=mp&s=160"},"body":"On Wed, Dec 17, 2008 at 3:30 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> The last part of the sentence after \"because\" does not parse for me at\n> all...\n\nSorry for the double/triple/quadruple negatives I threw in there.\nMakes the statement incredibly unclear.\n\n> , but I think you are after one of the following:\n>\n>  (1) if you want to get rid of garbage changes in your work tree, you\n>     would want \"git checkout $that_path\";\n>\n>  (2) if you want to temporarily stash away further changes in your work\n>     tree, because you would want to first test what is staged, commit it,\n>     and then later continue to refine the changes stashed away thusly,\n>     you would want \"git stash --keep-index\".\n>\n>\n\nIf I could attempt to make my situation a little clearer.\n\nI had two very similar files (I know, I know, DRY, blah blah. :\\ It's\nnot my source tree to begin with... bleh) and I wanted to duplicate a\nbunch of simple edits (adding white space, comments, etc.) from one of\nthem to the other without having to manually compare them.\n\nThen, a light bulb went off in my head and I thought to myself that it\nwould make a ton of sense to use `git add -i` to add only the changes\nthat I wanted to the files and leave the stuff I wanted to be\ndifferent between the two of them out.  I `cp`ed the edited file over\nthe other file and then fired up `git add -i` and proceeded to stage\nall of the edits that I wanted.  This left me with a staged version of\nthe file that was exactly what I wanted and a locally modified file\nwith contents that I didn't want.  However, the changes were still\nuntested.\n\nWhat I wanted to do was basically get rid of the unstaged edits on\nthis file but keep the staged ones.  Without committing.\n\nUnfortunately I couldn't figure out how to do this.  The solution I\ncame up with was to go ahead and `git commit` the staged changes and\nthen `git checkout PATH` the just committed file to overwrite the\nlocal edits with the version of the file I wanted.\n\nI want to know if it was possible to accomplish this without the commit stage.\n\n-- \n\nIn Christ,\n\nTimmy V.\n\nhttp://burningones.com/\nhttp://five.sentenc.es/ - Spend less time on e-mail\n"},{"id":"98200","messageId":"7vbpvajtmd.fsf@gitster.siamese.dyndns.org","threadId":"16771","inReplyTo":"c115fd3c0812171448o3db6f4c1oc24e39f9a68ed1d3@mail.gmail.com","subject":"Re: Is it possible to roll back unstaged changes while leaving the staged ones for the next commit?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-12-17T22:59:22Z","receivedAt":"2008-12-17T22:59:22Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Tim Visher\" <tim.visher@gmail.com> writes:\n\n> On Wed, Dec 17, 2008 at 3:30 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> ...\n>>  (1) if you want to get rid of garbage changes in your work tree, you\n>>     would want \"git checkout $that_path\";\n>>\n>>  (2) if you want to temporarily stash away further changes in your work\n>>     tree, because you would want to first test what is staged, commit it,\n>>     and then later continue to refine the changes stashed away thusly,\n>>     you would want \"git stash --keep-index\".\n> ...\n> Unfortunately I couldn't figure out how to do this.  The solution I\n> came up with was to go ahead and `git commit` the staged changes and\n> then `git checkout PATH` the just committed file to overwrite the\n> local edits with the version of the file I wanted.\n\nHow about omitting the \"git commit\" and do \"git checkout PATH\" after you\nare done with the staging?  IOW, (1) above.\n"},{"id":"98210","messageId":"c115fd3c0812171722g93dbeefw2fb5bf7641dfe394@mail.gmail.com","threadId":"16771","inReplyTo":"7vbpvajtmd.fsf@gitster.siamese.dyndns.org","subject":"Re: Is it possible to roll back unstaged changes while leaving the staged ones for the next commit?","fromName":"Tim Visher","fromEmail":"tim.visher@gmail.com","sentAt":"2008-12-18T01:22:17Z","receivedAt":"2008-12-18T01:22:17Z","isPatch":false,"sender":{"key":"tim.visher@gmail.com","avatar":"https://gravatar.com/avatar/98307ce54bcac1a46b5d845827d5386e2a27895ff08790cdd3877ad527760575?d=mp&s=160"},"body":"On Wed, Dec 17, 2008 at 5:59 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> How about omitting the \"git commit\" and do \"git checkout PATH\" after you\n> are done with the staging?  IOW, (1) above.\n\nHuh.  I guess I was under the impression that doing the `git checkout\nPATH` would destroy the staged content as well as the unstaged.  This\nisn't the case?\n\n-- \n\nIn Christ,\n\nTimmy V.\n\nhttp://burningones.com/\nhttp://five.sentenc.es/ - Spend less time on e-mail\n"},{"id":"98222","messageId":"20081218123456.6117@nanako3.lavabit.com","threadId":"16771","inReplyTo":"c115fd3c0812171722g93dbeefw2fb5bf7641dfe394@mail.gmail.com","subject":"Re: Is it possible to roll back unstaged changes while leaving the staged ones for the next commit?","fromName":"Nanako Shiraishi","fromEmail":"nanako3@lavabit.com","sentAt":"2008-12-18T03:34:56Z","receivedAt":"2008-12-18T03:34:56Z","isPatch":false,"sender":{"key":"nanako3@lavabit.com","avatar":"https://gravatar.com/avatar/3777b9e201c5883a62b1a6fdf7c53f2d712d1d80989146063ea861e33aad72a8?d=mp&s=160"},"body":"Quoting \"Tim Visher\" <tim.visher@gmail.com>:\n\n> On Wed, Dec 17, 2008 at 5:59 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> How about omitting the \"git commit\" and do \"git checkout PATH\" after you\n>> are done with the staging?  IOW, (1) above.\n>\n> Huh.  I guess I was under the impression that doing the `git checkout\n> PATH` would destroy the staged content as well as the unstaged.  This\n> isn't the case?\n\nA short answer is \"no it is not the case.\"\n\nI was about to quote \"git checkout\" documentation to you because I was reasonably sure that Junio won't respond to people who ask a question whose answer is plainly described in the manual pages, but I think the description of the command is a little confusing especially for people who read it for the first time.\n\nThis is a patch to clarify the sentence.\n\n-- 8< -- Cut Here -- 8< --\nSubject: Clarify documentation of \"git checkout <tree-ish> paths\" syntax\n\nThe SYNOPSIS section of the manual writes:\n\n    git checkout [options] [<tree-ish>] [--] <paths>...\n\nbut the DESCRIPTION says that this form checks the paths out \"from the\nindex, or from a named commit.\"  A later sentence refers to the same\nargument as \"<tree-ish> argument\", but it is not clear that these two\nsentences are talking about the same command line argument for first-time\nreaders.\n\nSigned-off-by: Nanako Shiraishi <nanako3@lavabit.com>\n---\n\n Documentation/git-checkout.txt |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt\nindex 168333a..bbdfa40 100644\n--- a/Documentation/git-checkout.txt\n+++ b/Documentation/git-checkout.txt\n@@ -27,7 +27,7 @@ the first namespace level.\n \n When <paths> are given, this command does *not* switch\n branches.  It updates the named paths in the working tree from\n-the index file, or from a named commit.  In\n+the index file, or from a named <tree-ish> (most often a commit).  In\n this case, the `-b` options is meaningless and giving\n either of them results in an error.  <tree-ish> argument can be\n used to specify a specific tree-ish (i.e. commit, tag or tree)\n\n\n\n\n\n\n\n\n-- \nNanako Shiraishi\nhttp://ivory.ap.teacup.com/nanako3/\n"},{"id":"98249","messageId":"c115fd3c0812180424q3ac080a8iad53803fd3f2bb4d@mail.gmail.com","threadId":"16771","inReplyTo":"20081218123456.6117@nanako3.lavabit.com","subject":"Re: Is it possible to roll back unstaged changes while leaving the staged ones for the next commit?","fromName":"Tim Visher","fromEmail":"tim.visher@gmail.com","sentAt":"2008-12-18T12:24:11Z","receivedAt":"2008-12-18T12:24:11Z","isPatch":false,"sender":{"key":"tim.visher@gmail.com","avatar":"https://gravatar.com/avatar/98307ce54bcac1a46b5d845827d5386e2a27895ff08790cdd3877ad527760575?d=mp&s=160"},"body":"On Wed, Dec 17, 2008 at 10:34 PM, Nanako Shiraishi <nanako3@lavabit.com> wrote:\n\n> A short answer is \"no it is not the case.\"\n\nThanks.\n\n> I was about to quote \"git checkout\" documentation to you because I was reasonably sure that Junio won't respond to people who ask a question whose answer is plainly described in the manual pages, but I think the description of the command is a little confusing especially for people who read it for the first time.\n\nAgreed.\n\n>  When <paths> are given, this command does *not* switch\n>  branches.  It updates the named paths in the working tree from\n>  the index file, or from a named <tree-ish> (most often a commit).  In\n>  this case, the `-b` options is meaningless and giving\n>  either of them results in an error.  <tree-ish> argument can be\n>  used to specify a specific tree-ish (i.e. commit, tag or tree)\n\nWorks a lot better.\n\nThanks for the help!\n\n-- \n\nIn Christ,\n\nTimmy V.\n\nhttp://burningones.com/\nhttp://five.sentenc.es/ - Spend less time on e-mail\n"}]}