3 ms·
The problem with stash is that its easy to create a mess. Yes, it's useful to quickly stash your work, switch to a different branch, do some quick fix, then go
by yarcob 6y ago
The problem with stash is that its easy to create a mess.
Yes, it's useful to quickly stash your work, switch to a different branch, do some quick fix, then go back to your original branch.
But in practice, what often happens is that your quick fix takes way longer than expected, and you don't immediately go back to your original branch.
Then you pull in some changes, maybe someone else pushed something to the branch you were working on, and you end up with a bunch of stashes on outdated branches and it's really hard to make sense of it all. Most of my working copies have at least half a dozen old stashes that I don't remember any details about anymore.
One approach to avoid this mess that git stash can lead to is to never use it, and just commit all your work before switching to a different branch. Clean up the current state of the repo, try to document your changes in the commit message, and commit them. Then switch branches.
You can always squash or rewrite the commits later, and it's a lot easier rebasing or merging a few old commits than working with stashes.
If you like stashes, please use them!
But I agree with the author, using them a lot can lead to a mess, and temporary branches are usually a cleaner way of saving your work.
- gtsteve 6y agoI personally only use stashes when I've given up on my current approach and want to reset but I might change my mind later (rarely happens). I don't think they're appropriate for stuff you want to keep across branches, there's no real visibility and they'd be easily forgotten.
- zikzak 6y agoI use them to stash changes to config files that remain fairly stable across branches but require local paths, etc. I realize this isn't a best practice for config files but it is what I need to do for my particular mountain of technical debt. This works particularly well since the config files rarely change in a permanent way. I will only do it short term, though. For me, Stash is a tool I use sparingly as a convenience.
- laudable-logic 6y ago> I use them to stash changes to config files that remain fairly stable across branches but require local paths, etc. I had to resort to git's assume-unchanged[O] to keep these changes out of commits made in the heat of battle. > this isn't a best practice for config files Have had great results (in dotnet land) with MS' Secrets Manager[1]. [0] https://www.git-scm.com/docs/git-update-index https://www.git-scm.com/docs/git-update-index [1] https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-3.1&tabs=windows#secret-manager https://docs.microsoft.com/en-us/aspnet/core/security/app-se...
- zikzak 6y agoThanks, I will review that. We are working on ASP.NET stuff and using Web.configs in a non-standard way (don't get me started) to store encrypted strings for... anyway, you get the idea. This is in the queue to get overhauled soon, so hopefully won't be an issue much longer (if you squint, you can see the end of the todo list wayyy back there). Maybe I should check this out.
- obelos 6y agoSame for me. I only ever use stash in cases where I don't materially care if I never see the content again, as with an experimental approach.
- wool_gather 6y agoI don't think there's anything wrong with stashes, but there's another interesting trick that you might want to try for this purpose: commit the dead-end, then immediately make a revert commit. You can even add a rationale in the revert commit message. The technique is not applicable all the time, but for those instances when you really think it's valuable to preserve the knowledge that was gained in trying and abandoning a particular approach it's great.
- mplanchard 6y agoI started using emacs recently, largely for org-mode and magit. The default stash behavior of prompting for a message in magit helps me a lot with the problem of keeping stashes organized and knowing when old stashes I’ve forgotten about are safe to get rid of. Even when working on the command line now, I try to always stash with a message to provide some context for future me.