{"thread":{"id":"56419","subject":"RE: Git stash certain files","startedAt":"2021-08-31T21:40:22Z","lastAt":"2021-08-31T22:09:47Z","messageCount":3,"participants":["Caleb Dougherty","Randall S. Becker"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"434367","messageId":"BN6PR17MB3185652B92D61670BC92ABA5FECC9@BN6PR17MB3185.namprd17.prod.outlook.com","threadId":"56419","inReplyTo":"BN6PR17MB31854E1EB7F8D358266B2AA8FECC9@BN6PR17MB3185.namprd17.prod.outlook.com","subject":"RE: Git stash certain files","fromName":"Caleb Dougherty","fromEmail":"caleb_dougherty@keysight.com","sentAt":"2021-08-31T21:17:49Z","receivedAt":"2021-08-31T21:40:22Z","isPatch":false,"sender":{"key":"caleb_dougherty@keysight.com","avatar":null},"body":"Hi,\n\nLet me know if I should post this somewhere else, but having used git now for a couple years in my work environment, and having come from years of TFS usage, I still find that I want the ability to \"shelve\" certain file changes for later.\n\nMy workflow is to create a personal branch and make changes to different parts of our codebase, and then stage certain files (not all) that are ready, and then commit them.  Sometimes I need to undo certain files in my working directory but keep the changes for later.\n\nGit stash will kind of allow that, but it is messy since it snapshots all my checked out files and I have to do several commands to get the operation of \"just stash these few files.\"\n\nHere is my \"shelve\" command.  Stage the files you want to shelve and then:\n                git commit -m '%1'\n                git switch -C shelveset/%username%/!shelvename!\n                git switch @{-1}\n                git reset --keep HEAD~\n\nHere is my \"unshelve\" command:\n\tset branch=shelveset/%username%/%1\n\tgit cherry-pick %branch%\n\tgit reset HEAD~\n\tgit branch -D %branch%\n\nIt would be nice if this were built into the stage command as an option (to only stash staged files), or perhaps a new shelve/unshelve set of commands could be added.  The additional niceties of shelve/unshelve is that it is on a branch that can be pushed to a remote (so I don't lose it in a moment of absentmindedness or computer failure) and potentially unshelved by someone else (\"Hey Joe, take a look at my code on shelveset xyz\").\n\nP.s. I cannot easily use the usual git workflow where you only do X feature change on X feature branch.  I work on multiple features in parallel and cannot be switching branches frequently or I will incur too much overhead (not only running the commands to do the switch).  \n\nRegards,\nCaleb\n\n"},{"id":"434368","messageId":"058f01d79eb3$c5001310$4f003930$@nexbridge.com","threadId":"56419","inReplyTo":"BN6PR17MB3185652B92D61670BC92ABA5FECC9@BN6PR17MB3185.namprd17.prod.outlook.com","subject":"RE: Git stash certain files","fromName":"Randall S. Becker","fromEmail":"rsbecker@nexbridge.com","sentAt":"2021-08-31T22:01:31Z","receivedAt":"2021-08-31T22:01:43Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On August 31, 2021 5:18 PM, Caleb Dougherty wrote:\n>Let me know if I should post this somewhere else, but having used git now for a couple years in my work environment, and having\ncome\n>from years of TFS usage, I still find that I want the ability to \"shelve\" certain file changes for later.\n>\n>My workflow is to create a personal branch and make changes to different parts of our codebase, and then stage certain files (not\nall) that\n>are ready, and then commit them.  Sometimes I need to undo certain files in my working directory but keep the changes for later.\n>\n>Git stash will kind of allow that, but it is messy since it snapshots all my checked out files and I have to do several commands to\nget the\n>operation of \"just stash these few files.\"\n>\n>Here is my \"shelve\" command.  Stage the files you want to shelve and then:\n>                git commit -m '%1'\n>                git switch -C shelveset/%username%/!shelvename!\n>                git switch @{-1}\n>                git reset --keep HEAD~\n>\n>Here is my \"unshelve\" command:\n>\tset branch=shelveset/%username%/%1\n>\tgit cherry-pick %branch%\n>\tgit reset HEAD~\n>\tgit branch -D %branch%\n>\n>It would be nice if this were built into the stage command as an option (to only stash staged files), or perhaps a new\nshelve/unshelve set of\n>commands could be added.  The additional niceties of shelve/unshelve is that it is on a branch that can be pushed to a remote (so I\ndon't\n>lose it in a moment of absentmindedness or computer failure) and potentially unshelved by someone else (\"Hey Joe, take a look at my\n>code on shelveset xyz\").\n>\n>P.s. I cannot easily use the usual git workflow where you only do X feature change on X feature branch.  I work on multiple\nfeatures in\n>parallel and cannot be switching branches frequently or I will incur too much overhead (not only running the commands to do the\nswitch).\n\nHave a look at git stash push -- <pathspec>... I think that might do what you want.\n-Randall\n\n"},{"id":"434370","messageId":"BN6PR17MB318540A1376CA1FACDE809DFFECC9@BN6PR17MB3185.namprd17.prod.outlook.com","threadId":"56419","inReplyTo":"058f01d79eb3$c5001310$4f003930$@nexbridge.com","subject":"RE: Git stash certain files","fromName":"Caleb Dougherty","fromEmail":"caleb_dougherty@keysight.com","sentAt":"2021-08-31T22:09:35Z","receivedAt":"2021-08-31T22:09:47Z","isPatch":false,"sender":{"key":"caleb_dougherty@keysight.com","avatar":null},"body":"Hi Randall,\n\nThanks for the suggestion.  I'm afraid it doesn't help that much because I can only use it from the command line.  Usually I stage my files using some UI, like SourceTree.  Otherwise it would be a lot of typing and or copying multiple paths.  Think along the lines of, I modified 10 files, and they are distributed across 5 directories with deep paths.\n\nRegards,\nCaleb\n\n-----Original Message-----\nFrom: Randall S. Becker <rsbecker@nexbridge.com> \nSent: Tuesday, August 31, 2021 3:02 PM\nTo: Caleb Dougherty <caleb_dougherty@keysight.com>; git@vger.kernel.org\nSubject: RE: Git stash certain files\n\nCAUTION: This message originates from an external sender.\n\nOn August 31, 2021 5:18 PM, Caleb Dougherty wrote:\n>Let me know if I should post this somewhere else, but having used git \n>now for a couple years in my work environment, and having\ncome\n>from years of TFS usage, I still find that I want the ability to \"shelve\" certain file changes for later.\n>\n>My workflow is to create a personal branch and make changes to \n>different parts of our codebase, and then stage certain files (not\nall) that\n>are ready, and then commit them.  Sometimes I need to undo certain files in my working directory but keep the changes for later.\n>\n>Git stash will kind of allow that, but it is messy since it snapshots \n>all my checked out files and I have to do several commands to\nget the\n>operation of \"just stash these few files.\"\n>\n>Here is my \"shelve\" command.  Stage the files you want to shelve and then:\n>                git commit -m '%1'\n>                git switch -C shelveset/%username%/!shelvename!\n>                git switch @{-1}\n>                git reset --keep HEAD~\n>\n>Here is my \"unshelve\" command:\n>       set branch=shelveset/%username%/%1\n>       git cherry-pick %branch%\n>       git reset HEAD~\n>       git branch -D %branch%\n>\n>It would be nice if this were built into the stage command as an option \n>(to only stash staged files), or perhaps a new\nshelve/unshelve set of\n>commands could be added.  The additional niceties of shelve/unshelve is \n>that it is on a branch that can be pushed to a remote (so I\ndon't\n>lose it in a moment of absentmindedness or computer failure) and \n>potentially unshelved by someone else (\"Hey Joe, take a look at my code on shelveset xyz\").\n>\n>P.s. I cannot easily use the usual git workflow where you only do X \n>feature change on X feature branch.  I work on multiple\nfeatures in\n>parallel and cannot be switching branches frequently or I will incur \n>too much overhead (not only running the commands to do the\nswitch).\n\nHave a look at git stash push -- <pathspec>... I think that might do what you want.\n-Randall\n\n"}]}