{"thread":{"id":"25684","subject":"Git automatic stashing?","startedAt":"2010-11-09T05:37:53Z","lastAt":"2010-11-09T19:19:09Z","messageCount":7,"participants":["Casey McGinty","Matthieu Moy","Martin von Zweigbergk","Nguyen Thai Ngoc Duy","Thomas Rast"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"155460","messageId":"AANLkTinwftXiZxbs_=PeM-MxQmMF4VaBCPEufH=OG6iU@mail.gmail.com","threadId":"25684","inReplyTo":"AANLkTim3MacQK6EtTPNJsYbqb=5bOM3W3BXC6p=hT+PU@mail.gmail.com","subject":"Git automatic stashing?","fromName":"Casey McGinty","fromEmail":"casey.mcginty@gmail.com","sentAt":"2010-11-09T05:37:53Z","receivedAt":"2010-11-09T05:37:53Z","isPatch":false,"sender":{"key":"casey.mcginty@gmail.com","avatar":null},"body":"Is there any feature in git to perform and auto stash apply/pop when\ntrying to do a merge/rebase in a dirty working dir? This would save\nsome keystrokes from time-to-time, and make it easier for new users\nunfamiliar with git.\n\nRegards,\nCasey McGinty\n"},{"id":"155464","messageId":"vpqlj53j5rv.fsf@bauges.imag.fr","threadId":"25684","inReplyTo":"AANLkTinwftXiZxbs_=PeM-MxQmMF4VaBCPEufH=OG6iU@mail.gmail.com","subject":"Re: Git automatic stashing?","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-11-09T07:49:24Z","receivedAt":"2010-11-09T07:49:24Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Casey McGinty <casey.mcginty@gmail.com> writes:\n\n> Is there any feature in git to perform and auto stash apply/pop when\n> trying to do a merge/rebase in a dirty working dir? This would save\n> some keystrokes from time-to-time, and make it easier for new users\n> unfamiliar with git.\n\nI agree with the keystrokes part, but not with the fact that it would\nmake it easier in general. In the sequence\n\ngit stash\ngit merge\ngit stash pop\n\nconflicts can occur in 2 distinct places. One can easily forsee this\nsenario occuring:\n\ngit stash\ngit merge\n# fix conflicts\n# git commit\n# forget to do the action needed to get the \"git stash pop\"\n\nand voila, you've just lost data.\n\nActually, what I'd like to see would be this feature, but limited to\nthe case where the merge is a fast-forward, because then, only the\nlast action of the sequence could possibly leave conflict, so Git\ncould finish with a message like \"please fix conflicts and continue\nworking\". Actually, this is not far from what \"git checout -m\" is\ndoing.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"155478","messageId":"AANLkTi=L7WUPP_9ZmUmNKqYvQzpZFau4F0nWNxdLy1sZ@mail.gmail.com","threadId":"25684","inReplyTo":"vpqlj53j5rv.fsf@bauges.imag.fr","subject":"Re: Git automatic stashing?","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-09T12:02:22Z","receivedAt":"2010-11-09T12:02:22Z","isPatch":false,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"On Tue, Nov 9, 2010 at 2:49 AM, Matthieu Moy\n<Matthieu.Moy@grenoble-inp.fr> wrote:\n> Casey McGinty <casey.mcginty@gmail.com> writes:\n>\n>> Is there any feature in git to perform and auto stash apply/pop when\n>> trying to do a merge/rebase in a dirty working dir? This would save\n>> some keystrokes from time-to-time, and make it easier for new users\n>> unfamiliar with git.\n>\n> I agree with the keystrokes part, but not with the fact that it would\n> make it easier in general. In the sequence\n>\n> git stash\n> git merge\n> git stash pop\n>\n> conflicts can occur in 2 distinct places. [...]\n\nCorrect me if I'm wrong, but I think git will only stop you from\nperforming a merge if it would involve touching any of your dirty files,\nso in the case of merge, I agree with Matthieu that temporarily stashing\nyour changes would probably just increase the risk of confusing the\nuser.\n\nHowever, in the case of rebase, git will not let you rebase if *any*\nfile is dirty. So, in this case of rebase, there are often cases where\ngit prevents a rebase that could have been a stash + rebase + stash pop\nwithout any conflicts in the pop step.\n\nI know that the fact that 'git rebase' (usually in the form of a\n'git pull' configured for rebase on the current branch) forces the user\nto temporarily stash his changes has been somewhat annoying to some of\nmy colleagues.\n\nI actually implemented support for stashing changes using 'stash create'\nand 'stash apply', but only for non-interactive rebase. The implentation\nsupports a '--stash' argument and a 'rebase.stash' configuration. I am\ncurrently working on refactoring git-rebase.sh and\ngit-rebase--interactive.sh, but once that's done, I will post an updated\nversion of the 'git rebase --stash' patch(es).\n\nI later found out that this seems to have been attempted at least twice\nbefore. The first time by Junio in 6c9ad16 (rebase: allow starting from\na dirty tree., 2007-07-09). This was later reverted. I think it was\nreverted because the stashing was not optional.\n\nSome months later, Simon Sasburg sent some patches on the same subject,\nsee http://thread.gmane.org/gmane.comp.version-control.git/63007/. These\npatches don't see to have been accepted, but I'm not sure why.\n"},{"id":"155482","messageId":"AANLkTi=G=Xo90QayvuRDp=GTWtkES2fU0kkmn87Q09_2@mail.gmail.com","threadId":"25684","inReplyTo":"AANLkTinwftXiZxbs_=PeM-MxQmMF4VaBCPEufH=OG6iU@mail.gmail.com","subject":"Re: Git automatic stashing?","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-11-09T12:36:02Z","receivedAt":"2010-11-09T12:36:02Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Nov 9, 2010 at 12:37 PM, Casey McGinty <casey.mcginty@gmail.com> wrote:\n> Is there any feature in git to perform and auto stash apply/pop when\n> trying to do a merge/rebase in a dirty working dir? This would save\n> some keystrokes from time-to-time, and make it easier for new users\n> unfamiliar with git.\n\nAnd when switching branches too.\n-- \nDuy\n"},{"id":"155485","messageId":"AANLkTin-qFrTnu+ZUx45Gbk_3m3843T1+n+aj3agwfzD@mail.gmail.com","threadId":"25684","inReplyTo":"AANLkTi=G=Xo90QayvuRDp=GTWtkES2fU0kkmn87Q09_2@mail.gmail.com","subject":"Re: Git automatic stashing?","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-09T12:58:07Z","receivedAt":"2010-11-09T12:58:07Z","isPatch":false,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"On Tue, Nov 9, 2010 at 7:36 AM, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:\n> On Tue, Nov 9, 2010 at 12:37 PM, Casey McGinty <casey.mcginty@gmail.com> wrote:\n>> Is there any feature in git to perform and auto stash apply/pop when\n>> trying to do a merge/rebase in a dirty working dir? This would save\n>> some keystrokes from time-to-time, and make it easier for new users\n>> unfamiliar with git.\n>\n> And when switching branches too.\n\nWhen switching branches (or checking out a different commit in general),\nI think git allows you to check out as long as the files that need to be\nreplaced have not been updated, much like when merging. As far as I can\nsee, that makes the benefit of temporarily stashing changes much smaller\n(but not non-existent) in these two cases (checkout and merge) than it\nis when rebasing.\n\nThinking a bit more about it, I think you are right, though, that it\nwould still be a nice-to-have, as an option. Currently, 'git rebase' is\nmore restrictive than 'git merge', but adding the option to 'git rebase'\nwould not just make it on par with 'git merge', but would actually make\nit less restrictive than 'git merge', as even non-conflicting changes\nwithin files would be automatically handled.\n"},{"id":"155505","messageId":"vpqd3qe8g5j.fsf@bauges.imag.fr","threadId":"25684","inReplyTo":"AANLkTi=G=Xo90QayvuRDp=GTWtkES2fU0kkmn87Q09_2@mail.gmail.com","subject":"Re: Git automatic stashing?","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-11-09T19:12:56Z","receivedAt":"2010-11-09T19:12:56Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n\n> On Tue, Nov 9, 2010 at 12:37 PM, Casey McGinty <casey.mcginty@gmail.com> wrote:\n>> Is there any feature in git to perform and auto stash apply/pop when\n>> trying to do a merge/rebase in a dirty working dir? This would save\n>> some keystrokes from time-to-time, and make it easier for new users\n>> unfamiliar with git.\n>\n> And when switching branches too.\n\nIsn't that what \"git checkout -m\" does?\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"155506","messageId":"201011092019.09239.trast@student.ethz.ch","threadId":"25684","inReplyTo":"vpqd3qe8g5j.fsf@bauges.imag.fr","subject":"Re: Git automatic stashing?","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-11-09T19:19:09Z","receivedAt":"2010-11-09T19:19:09Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Matthieu Moy wrote:\n> Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n> \n> > On Tue, Nov 9, 2010 at 12:37 PM, Casey McGinty <casey.mcginty@gmail.com> wrote:\n> >> Is there any feature in git to perform and auto stash apply/pop when\n> >> trying to do a merge/rebase in a dirty working dir? This would save\n> >> some keystrokes from time-to-time, and make it easier for new users\n> >> unfamiliar with git.\n> >\n> > And when switching branches too.\n> \n> Isn't that what \"git checkout -m\" does?\n\nThe problem with checkout -m is that you get only a single shot at\nconflict resolution.  'git stash pop' does not drop the stash in the\ncase of a conflict, so you can try again.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"}]}