{"thread":{"id":"25623","subject":"Problems switching branches","startedAt":"2010-11-03T02:37:31Z","lastAt":"2010-11-24T22:33:04Z","messageCount":6,"participants":["Maaartin","Nguyen Thai Ngoc Duy","Maaartin-1","Neal Kreitzinger"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"155015","messageId":"loom.20101103T032930-451@post.gmane.org","threadId":"25623","inReplyTo":null,"subject":"Problems switching branches","fromName":"Maaartin","fromEmail":"grajcar1@seznam.cz","sentAt":"2010-11-03T02:37:31Z","receivedAt":"2010-11-03T02:37:31Z","isPatch":false,"sender":{"key":"grajcar1@seznam.cz","avatar":null},"body":"I sometimes run in a problem similar to\nhttp://kerneltrap.org/mailarchive/git/2008/10/15/3667644/thread\nThere are some ignored files which I want neither track nor throw away; I'm just \nhappy to have them and keep them out of version control.\n\nUnfortunately, there weren't ignored in the old branch. I'd be quite happy with \nnon-destructive switching like \"checkout everything what doesn't overwrite an \nuntracked file\", so I would end in the old branch with a dirty working tree. Is \nit possible?\n"},{"id":"155096","messageId":"loom.20101104T012032-963@post.gmane.org","threadId":"25623","inReplyTo":"loom.20101103T032930-451@post.gmane.org","subject":"Re: Problems switching branches","fromName":"Maaartin","fromEmail":"grajcar1@seznam.cz","sentAt":"2010-11-04T00:23:03Z","receivedAt":"2010-11-04T00:23:03Z","isPatch":false,"sender":{"key":"grajcar1@seznam.cz","avatar":null},"body":"Maaartin <grajcar1 <at> seznam.cz> writes:\n\n> \n> I sometimes run in a problem similar to\n> http://kerneltrap.org/mailarchive/git/2008/10/15/3667644/thread\n> There are some ignored files which I want neither track nor throw away; I'm \njust \n> happy to have them and keep them out of version control.\n> \n> Unfortunately, there weren't ignored in the old branch. I'd be quite happy \nwith \n> non-destructive switching like \"checkout everything what doesn't overwrite an \n> untracked file\", so I would end in the old branch with a dirty working tree. \nIs \n> it possible?\n\nNo answer? In the meantime I've found a simple workaround: Checkout the old \nbranch in another directory, modify .gitignore, commit and retry. But this is \nfar from cool. Am I doing something stupid and nobody else ran into this?\n"},{"id":"155170","messageId":"AANLkTikK93Jt+dAkpp6K-hQEo6D67q5OKJSLs+g0YL4y@mail.gmail.com","threadId":"25623","inReplyTo":"loom.20101104T012032-963@post.gmane.org","subject":"Re: Problems switching branches","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-11-04T14:39:49Z","receivedAt":"2010-11-04T14:39:49Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Nov 4, 2010 at 7:23 AM, Maaartin <grajcar1@seznam.cz> wrote:\n> Maaartin <grajcar1 <at> seznam.cz> writes:\n>\n>>\n>> I sometimes run in a problem similar to\n>> http://kerneltrap.org/mailarchive/git/2008/10/15/3667644/thread\n>> There are some ignored files which I want neither track nor throw away; I'm\n> just\n>> happy to have them and keep them out of version control.\n>>\n>> Unfortunately, there weren't ignored in the old branch. I'd be quite happy\n> with\n>> non-destructive switching like \"checkout everything what doesn't overwrite an\n>> untracked file\", so I would end in the old branch with a dirty working tree.\n> Is\n>> it possible?\n>\n> No answer?\n\nWhich means nobody is interested in. Well, not really.\n\nI also get irritated by a similar situation, where the untracked files\nhave the same content as the to-be-checked-out files. I have been\ntempted (but never got around) to make git compare the in-index\ncontent and the untracked file, if it's the same, no need to abort the\ncheckout process.\n\nBut your approach may be better. Yes, I think it's possible. Any\nsuggestion for checkout's new argument? --no-overwrite-untracked seems\ntoo long.\n-- \nDuy\n"},{"id":"155245","messageId":"4CD3A5D9.6070802@seznam.cz","threadId":"25623","inReplyTo":"AANLkTikK93Jt+dAkpp6K-hQEo6D67q5OKJSLs+g0YL4y@mail.gmail.com","subject":"Re: Problems switching branches","fromName":"Maaartin-1","fromEmail":"grajcar1@seznam.cz","sentAt":"2010-11-05T06:36:09Z","receivedAt":"2010-11-05T06:36:09Z","isPatch":false,"sender":{"key":"grajcar1@seznam.cz","avatar":null},"body":"On 10-11-04 15:39, Nguyen Thai Ngoc Duy wrote:\n> On Thu, Nov 4, 2010 at 7:23 AM, Maaartin <grajcar1@seznam.cz> wrote:\n>> Maaartin <grajcar1 <at> seznam.cz> writes:\n>>\n>>>\n>>> I sometimes run in a problem similar to\n>>> http://kerneltrap.org/mailarchive/git/2008/10/15/3667644/thread\n>>> There are some ignored files which I want neither track nor throw away; I'm\n>> just\n>>> happy to have them and keep them out of version control.\n>>>\n>>> Unfortunately, there weren't ignored in the old branch. I'd be quite happy\n>> with\n>>> non-destructive switching like \"checkout everything what doesn't overwrite an\n>>> untracked file\", so I would end in the old branch with a dirty working tree.\n>> Is\n>>> it possible?\n>>\n>> No answer?\n> \n> Which means nobody is interested in. Well, not really.\n> \n> I also get irritated by a similar situation, where the untracked files\n> have the same content as the to-be-checked-out files. I have been\n> tempted (but never got around) to make git compare the in-index\n> content and the untracked file, if it's the same, no need to abort the\n> checkout process.\n\nI was asked to provide a working example of the happening, but I haven't\nmanaged to reproduce it yet. However, it's not very rare (it just never\nhappen when I need it).\n\n> But your approach may be better. Yes, I think it's possible. Any\n> suggestion for checkout's new argument? --no-overwrite-untracked seems\n> too long.\n\nI would go even further: a switch called \"ignorant\" or \"lenient\"\nallowing to always switch branches in a non-destructible way. All files\nnormally causing abort would be left unmodified, so you could do\ngit checkout --ignorant forth; git checkout back\nand would (assuming you started in branch \"back\") land in the original\nstate without loosing anything. Of course, this means, that the ignorant\ncheckout doesn't lead you into a clean state, but that's why I'd like to\nuse a switch instead of making it the default. :)\n\nI may be talking non-sense as I'm quite inexperienced user, however I'd\nlove an easier way for switching branches. Quite often, I'd like to put\na modified file onto a different branch. This sounds probably strange,\nbut my work is really quite chaotic in this respect at the moment and\nI'd like to organize it better by using a couple of (quite similar)\nbranches (with a lifespan of a few days at most).\n"},{"id":"155252","messageId":"AANLkTinN7xE5eR7ncyr+mVhyNbz1r5Au=LFCJQgh8fMr@mail.gmail.com","threadId":"25623","inReplyTo":"4CD3A5D9.6070802@seznam.cz","subject":"Re: Problems switching branches","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-11-05T08:41:52Z","receivedAt":"2010-11-05T08:41:52Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, Nov 5, 2010 at 1:36 PM, Maaartin-1 <grajcar1@seznam.cz> wrote:\n>> But your approach may be better. Yes, I think it's possible. Any\n>> suggestion for checkout's new argument? --no-overwrite-untracked seems\n>> too long.\n>\n> I would go even further: a switch called \"ignorant\" or \"lenient\"\n> allowing to always switch branches in a non-destructible way. All files\n> normally causing abort would be left unmodified, so you could do\n> git checkout --ignorant forth; git checkout back\n> and would (assuming you started in branch \"back\") land in the original\n> state without loosing anything. Of course, this means, that the ignorant\n> checkout doesn't lead you into a clean state, but that's why I'd like to\n> use a switch instead of making it the default. :)\n\nOne thing to consider. If there are conflicts, I don't think we should\nallow this \"ignorant\" mode. That would mess up work tree in a bad way.\nAnd because it would leave worktree in a dirty state, maybe\n--dirty-worktree is suggestive.\n-- \nDuy\n"},{"id":"156510","messageId":"ick3tr$j5l$1@dough.gmane.org","threadId":"25623","inReplyTo":"4CD3A5D9.6070802@seznam.cz","subject":"Re: Problems switching branches","fromName":"Neal Kreitzinger","fromEmail":"neal@rsss.com","sentAt":"2010-11-24T22:33:04Z","receivedAt":"2010-11-24T22:33:04Z","isPatch":false,"sender":{"key":"neal@rsss.com","avatar":null},"body":"\n\"Maaartin-1\" <grajcar1@seznam.cz> wrote in message \nnews:4CD3A5D9.6070802@seznam.cz...\n> On 10-11-04 15:39, Nguyen Thai Ngoc Duy wrote:\n>> On Thu, Nov 4, 2010 at 7:23 AM, Maaartin <grajcar1@seznam.cz> wrote:\n>>> Maaartin <grajcar1 <at> seznam.cz> writes:\n>>>\n>>>>\n>>>> I sometimes run in a problem similar to\n>>>> http://kerneltrap.org/mailarchive/git/2008/10/15/3667644/thread\n>>>> There are some ignored files which I want neither track nor throw away; \n>>>> I'm\n>>> just\n>>>> happy to have them and keep them out of version control.\n>>>>\n>>>> Unfortunately, there weren't ignored in the old branch. I'd be quite \n>>>> happy\n>>> with\n>>>> non-destructive switching like \"checkout everything what doesn't \n>>>> overwrite an\n>>>> untracked file\", so I would end in the old branch with a dirty working \n>>>> tree.\n>>> Is\n>>>> it possible?\n>>>\n>>> No answer?\n>>\n>> Which means nobody is interested in. Well, not really.\n>>\n>> I also get irritated by a similar situation, where the untracked files\n>> have the same content as the to-be-checked-out files. I have been\n>> tempted (but never got around) to make git compare the in-index\n>> content and the untracked file, if it's the same, no need to abort the\n>> checkout process.\n>\n> I was asked to provide a working example of the happening, but I haven't\n> managed to reproduce it yet. However, it's not very rare (it just never\n> happen when I need it).\n>\n>> But your approach may be better. Yes, I think it's possible. Any\n>> suggestion for checkout's new argument? --no-overwrite-untracked seems\n>> too long.\n>\n> I would go even further: a switch called \"ignorant\" or \"lenient\"\n> allowing to always switch branches in a non-destructible way. All files\n> normally causing abort would be left unmodified, so you could do\n> git checkout --ignorant forth; git checkout back\n> and would (assuming you started in branch \"back\") land in the original\n> state without loosing anything. Of course, this means, that the ignorant\n> checkout doesn't lead you into a clean state, but that's why I'd like to\n> use a switch instead of making it the default. :)\n>\n> I may be talking non-sense as I'm quite inexperienced user, however I'd\n> love an easier way for switching branches. Quite often, I'd like to put\n> a modified file onto a different branch. This sounds probably strange,\n> but my work is really quite chaotic in this respect at the moment and\n> I'd like to organize it better by using a couple of (quite similar)\n> branches (with a lifespan of a few days at most).\n>\n\nYou could use git-stash in combination with git-clean.  Let's say BranchA \nhas FileA (untracked), and BranchB has FileA (tracked):\ngit branch = BranchA\ngit stash = this will store your dirty working tree in a commit \nbehind-the-scenes, and store your index in a commit behind-the-scenes, and \nthen run a git-reset --hard behind the scenes.\ngit status = is FileA still 'untracked'?\n    if so, git clean -f to remove it.  don't worry, its in your stash you \njust made.\ngit clean -f\ngit checkout BranchB\nnow you have FileA from BranchB\ngit checkout BranchA\ngit stash apply, (use git stash apply --index if you want the index back \nalso)\nnow you have BranchA and its untracked FileA\n\nUsing the stash and clean will also keep various untracked files from \ndifferent lines-of-development from accumulating in your worktree.  \"Keep \ntrack\" of your untracked files by stashing them away and cleaning them up, \nso to speak.  This is actually pretty straightforwarad and easy once you get \nused to it, IMHO.\n\nv/r,\nNeal \n"}]}