{"thread":{"id":"52334","subject":"Fwd: [BUG] \"git checkout BRANCH -- FILE\" deletes staged commits","startedAt":"2019-11-25T20:18:11Z","lastAt":"2019-11-26T22:07:09Z","messageCount":2,"participants":["Tasnad Kernetzky","Brandon McCaig"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"387014","messageId":"b1898690-667b-f413-7ac1-08ef733e7fa5@gmail.com","threadId":"52334","inReplyTo":"aaa2b05a-4c0c-8194-6488-f1b770f3b852@gmail.com","subject":"Fwd: [BUG] \"git checkout BRANCH -- FILE\" deletes staged commits","fromName":"Tasnad Kernetzky","fromEmail":"tasnadk@gmail.com","sentAt":"2019-11-25T20:18:05Z","receivedAt":"2019-11-25T20:18:11Z","isPatch":false,"sender":{"key":"tasnadk@gmail.com","avatar":null},"body":"Hi Brandon,\n\nThanks for your deep inspection!\n\nI know that the checkout command I was using was supposed to overwrite\nthe file, but I didn't know that it automatically stages changes. So I\nagree, that step makes sense and I should have rtfm.\n\nMy only suggestion for the docs would be to add \"staging\" or so to the\nsentence \"When a |<tree-ish>| is given, the paths that match the\n|<pathspec>| are updated both in the index and in the working tree.\".\nHowever, I think it's also clear enough as-is, so I don't see much room\nfor improvement there.\n\nPlease find my last comment in-line.\n\n\nBest,\n\nTasnad\n\n\nOn 22.11.19 04:14, Brandon McCaig wrote:\n[...]\n> When you switch back to branch B the state of the tst file is the\n> same as it exists in the branch B. There is no conflict here so\n> it succeeds, and once it does you no longer have any changes made\n> to tst because the version in your index and working tree matches\n> the version in the HEAD commit.\n>\n> git status at this point would report nothing (assuming no other\n> files are modified).\n\nThis is the point I actually considered as a bug. There are staged\nchanges and usually git doesn't let me switch away from a branch in such\ncases.\n\nAlthough I don't lose data, I do lose the newest state of the master\nbranch, if I'm not cautious and remember that I copied over changed from\n\"B\".\n\nI would prefere at least a warning :) \n\n"},{"id":"387112","messageId":"20191126220705.5kfrqdtzbfsgu2k3@test-chamber-21.localdomain","threadId":"52334","inReplyTo":"aaa2b05a-4c0c-8194-6488-f1b770f3b852@gmail.com","subject":"Re: [BUG] \"git checkout BRANCH -- FILE\" deletes staged commits","fromName":"Brandon McCaig","fromEmail":"bamccaig@gmail.com","sentAt":"2019-11-26T22:07:05Z","receivedAt":"2019-11-26T22:07:09Z","isPatch":false,"sender":{"key":"bamccaig@gmail.com","avatar":"https://gravatar.com/avatar/05b01f2b62a5ddbaa1946579266a8d9e970fed0c0b3c20e8d42aca973c31531c?d=mp&s=160"},"body":"Tasnad:\n\nOn Mon, Nov 25, 2019 at 09:15:18PM +0100, Tasnad Kernetzky wrote:\n> Hi Brandon,\n\nHello,\n\n> On 22.11.19 04:14, Brandon McCaig wrote: [...]\n> > When you switch back to branch B the state of the tst file is\n> > the same as it exists in the branch B. There is no conflict\n> > here so it succeeds, and once it does you no longer have any\n> > changes made to tst because the version in your index and\n> > working tree matches the version in the HEAD commit.\n> >\n> > git status at this point would report nothing (assuming no\n> > other files are modified).\n> \n> This is the point I actually considered as a bug. There are\n> staged changes and usually git doesn't let me switch away from\n> a branch in such cases.\n\nI think that Git normally will let you change branches even if\nyou have changes in your index or working tree as long as the\nversion of the file in your destination branch matches the HEAD\nversion. In other words no merge is necessary and no changes can\nbe lost. I regularly do this when I start making changes on\ndevelop or master, and then decide to branch after the fact. It's\na bit less typing than stashing in between. :)\n\nFor example:\n\n\tgit init checkout\n\tcd checkout\n\techo master >log\n\tgit add log\n\tgit commit -m master\n\tgit checkout -b B\n\techo B >>log\n\tgit add log\n\tgit checkout master\n\tgit status\n\nRegards,\n\n\n-- \nBrandon McCaig <bamccaig@gmail.com> <bambams@castopulence.org>\nCastopulence Software <https://www.castopulence.org/>\nBlog <http://www.bambams.ca/>\nperl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.\nq{Vg qbrfa'\\''g nyjnlf fbhaq gung jnl.};\ntr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'\n\n"}]}