{"thread":{"id":"20020","subject":"newbie question","startedAt":"2009-07-03T18:39:45Z","lastAt":"2009-07-06T12:11:53Z","messageCount":5,"participants":["Alex K","dloewenherz@gmail.com","Junio C Hamano","Sitaram Chamarty","Michael J Gruber"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"117423","messageId":"e4a904790907031139rc61c2e0t6b9dbbc0c3dc379e@mail.gmail.com","threadId":"20020","inReplyTo":null,"subject":"newbie question","fromName":"Alex K","fromEmail":"spaceoutlet@gmail.com","sentAt":"2009-07-03T18:39:45Z","receivedAt":"2009-07-03T18:39:45Z","isPatch":false,"sender":{"key":"spaceoutlet@gmail.com","avatar":null},"body":"Hello,\n\nI would think the following simple pattern would be possible:\n\nCreate two branches A and B. Switch to A, modify some files, do not\ncommit to A, switch to B. Now B should not show any of the changes\nperformed to A? However a git status while on B does show that the\nfiles on A have been modified. Is there something I am missing?\n\nThank you,\n\nAlex\n"},{"id":"117424","messageId":"20090703191230.GA2446@andros","threadId":"20020","inReplyTo":"e4a904790907031139rc61c2e0t6b9dbbc0c3dc379e@mail.gmail.com","subject":"Re: newbie question","fromName":"","fromEmail":"dloewenherz@gmail.com","sentAt":"2009-07-03T19:12:30Z","receivedAt":"2009-07-03T19:12:30Z","isPatch":false,"sender":{"key":"dloewenherz@gmail.com","avatar":"https://gravatar.com/avatar/69134b10dc6663fd8a4ac95edc0e556662c43c3acb226cec9f697cb8848198b2?d=mp&s=160"},"body":"Until you commit the files, the changes will follow you to whatever branch\nyou go to. If you don't want to commit, but still want to switch to B and\nnot see the changes in A, I would recommend using `git stash`.\n\ne.g.\n\ngit checkout A\n...edit...\ngit stash save changes\ngit checkout B\ngit status\n\nYou'll see that your tree is clean. To get your changes back to A, just run\n\ngit checkout A\ngit stash pop changes\n\nBest,\nDan\n\nOn 03/07/09 11:39 -0700, Alex K wrote:\n>Hello,\n>\n>I would think the following simple pattern would be possible:\n>\n>Create two branches A and B. Switch to A, modify some files, do not\n>commit to A, switch to B. Now B should not show any of the changes\n>performed to A? However a git status while on B does show that the\n>files on A have been modified. Is there something I am missing?\n>\n>Thank you,\n>\n>Alex\n>--\n>To unsubscribe from this list: send the line \"unsubscribe git\" in\n>the body of a message to majordomo@vger.kernel.org\n>More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"117425","messageId":"7vvdm9r2pi.fsf@alter.siamese.dyndns.org","threadId":"20020","inReplyTo":"e4a904790907031139rc61c2e0t6b9dbbc0c3dc379e@mail.gmail.com","subject":"Re: newbie question","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-07-03T19:22:49Z","receivedAt":"2009-07-03T19:22:49Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex K <spaceoutlet@gmail.com> writes:\n\n> I would think the following simple pattern would be possible:\n>\n> Create two branches A and B. Switch to A, modify some files, do not\n> commit to A, switch to B. Now B should not show any of the changes\n> performed to A? However a git status while on B does show that the\n> files on A have been modified. Is there something I am missing?\n\nYes, you are missing the basic concept of how git works and how to work\nwith git.\n\n\"Switch to A, modify some files, do not commit to A\".\n\nThe modification does _not_ belong to A at this point yet.\n\nThen you \"switch to B.\"  At this point, you switched branches and carried\nyour modification along with you.  B does _not_ show any of the changes\nperformed to A, as you never committed to A yet.\n\nWhat you see is the changes you performed to your _work tree_ (and your\n_index_, if you are using it).\n\nAnd this is a deliberately designed behaviour.  When you start hacking on\nsomething, you often do not know many things a-priori, including\n\n - if the change is small and simple enough that you can finish it in a\n   single sitting;\n\n - what is the oldest branch that the change is necessary\n\nThe former means that you may start working on a cool feature while you\nhave a checkout of your 'master' branch, but then you realize that the\nnecessary changes are much more involved than what you originally thought,\nand you are better off building that feature on a new side branch while\nyou have to work on completing it, and in the meantime, you would want to\nkeep your 'master' branch clean, so you do _not_ want to commit any of\nthis work-in-progress there.  So the behaviour allows you to do this:\n\n    $ hack hack hack ;# yeah, looking good\n    $ hack hack      ;# oops, this is a bit more complex than I thought\n    $ git checkout -b cool-feature\n    $ hack more ;# good point to snapshot even though it is not complete\n    $ git commit \n    $ hack even more ;# oops, boss tells me to fix something else right away\n    $ git commit -a -m 'WIP' ;# I'll come back to it later\n    $ git checkout master\n    $ work test work test ;# handle boss's wish\n    $ git commit -a -m 'Urgent fix'\n    $ git push origin master ;# emergency handled well\n    $ git checkout cool-feature\n    $ hadk hack ;# continue working\n    ...\n\nNotice the third step where you switch to the branch cool-feature (newly\ncreated).  You are taking your changes up to that point in your work tree\nalong with you when starting to work in that branch, and it is a good\nthing.\n\nThe latter means that you may start fixing a bug while you have a checkout\nof your 'master' branch, but then realize that the bug has existed from a\nlong time ago, and the same fix needs to go to your maintenance branch.\nAgain, the behaviour allows you to do this:\n\n    $ fix test fix test ;# Ok, I think it is good.\n    $ git blame HEAD -- broken.rb ;# where did this bug came from anyway?\n    ... find the commit that introduced the bug from the above blame ...\n    $ git branch --with $commit ;# on which branches is the bad commit in?\n    ... realize that the maintenance branch also has the same bug ...\n    $ git checkout maint\n    $ test it again\n    $ git commit ;# commit fix to the oldest applicable branch\n    $ git checkout master\n    $ git merge maint ;# and propagate it upwards\n\nAgain, notice that the \"checkout\" to switch to the 'maint' branch takes\nthe changes in your work tree along with you, and that is what allows you\nto fix the bug in the oldest applicable branch.\n\nIt also happens that you notice an unrelated breakage while working on\nsomething on a topic branch 'feature', and realize that the breakage is\ngrave enough that you should fix it on 'master' branch.  You would do\nthis:\n\n    $ git checkout feature ;# let's do a cool feature\n    $ edit feature.rb ;# yeah, looking good\n    $ edit broken.rb ;# this is unrelated\n    $ git checkout master\n    $ git add broken.rb ;# only add the fix to the index\n    $ git commit -m 'Fix' ;# never use \"commit -a\" when you do this\n    $ git checkout feature ;# continue working\n\nAgain, because the changes to broken.rb (together with the changes to\nfeature.rb) are carried across branch switching, you can fix the buggy  \ncode on your master branch, and come back (again, taking the changes to\nfeature.rb with you) to continue.\n"},{"id":"117430","messageId":"slrnh4t8jo.b72.sitaramc@sitaramc.homelinux.net","threadId":"20020","inReplyTo":"7vvdm9r2pi.fsf@alter.siamese.dyndns.org","subject":"Re: newbie question","fromName":"Sitaram Chamarty","fromEmail":"sitaramc@gmail.com","sentAt":"2009-07-04T00:29:44Z","receivedAt":"2009-07-04T00:29:44Z","isPatch":false,"sender":{"key":"sitaramc@gmail.com","avatar":"https://avatars.githubusercontent.com/u/43316?v=4"},"body":"On 2009-07-03 19:22:49, Junio C Hamano <gitster@pobox.com> wrote:\n\n>     $ git branch --with $commit ;# on which branches is the bad commit in?\n\n--with?  Did --contains get an alternative form?\n"},{"id":"117500","messageId":"4A51EA09.2000309@drmicha.warpmail.net","threadId":"20020","inReplyTo":"slrnh4t8jo.b72.sitaramc@sitaramc.homelinux.net","subject":"Re: newbie question","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-07-06T12:11:53Z","receivedAt":"2009-07-06T12:11:53Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Sitaram Chamarty venit, vidit, dixit 04.07.2009 02:29:\n> On 2009-07-03 19:22:49, Junio C Hamano <gitster@pobox.com> wrote:\n> \n>>     $ git branch --with $commit ;# on which branches is the bad commit in?\n> \n> --with?  Did --contains get an alternative form?\n> \n\nNo, it always had one :)\n\ngit log -S'\"with\"' --pretty=oneline\n694a577519a762d12b8a53e76b6f1dd3ccf25e7d git-branch --contains=commit\n\nCheers,\nMichael\n"}]}