4 ms·
I dislike the apparent inability to label groups of changes with `git stash`, so instead before leaving a branch with in-progress changes I'll commit them all a
by samhh 7y ago
I dislike the apparent inability to label groups of changes with `git stash`, so instead before leaving a branch with in-progress changes I'll commit them all as "WIP". Then, when I return to the branch, I'll check if the previous commit was WIP (`git log -1`), and if so will reset it (`git reset HEAD~1`). It's the best workflow I've discovered for dealing with this problem, and it means that I don't lose my commit history which is otherwise very clean.
- glandium 7y agogit stash save my stuff (deprecated) git stash push -m "my stuff"
- Sharlin 7y agoWhat GP wanted was to stash a history of commits, not just the current state of the working tree. `git stash` is fundamentally unable to do that.
- johnmaguire2013 7y agoThat's just called a branch. What GP described was committing all their changes into a single WIP commit.
- wtetzner 7y agoThey were describing many different WIP commits, and then later squashing them to a "proper" commit.
- johnmaguire2013 7y agoThat's a branch. > Then, when I return to the branch, I'll check if the previous commit was WIP (`git log -1`), and if so will reset it (`git reset HEAD~1`). This is a single commit.
- Sharlin 7y agoTemp branches or tags are probably the "proper" way to stash a history of changes in git. `git stash` is mostly a convenience feature for when you want to quickly clean up your working tree to eg. pull latest changes from a remote.
- rurp 7y agoI like the approach of creating a new temporary branch for changes I need to stash. When I come back to the work I usually bring the changes back to the branch I'm working in with `git cherry-pick -n <commit hash>`. The -n flag cherry picks the changes over without making a new commit, so I can finish whatever I was doing and then make a proper commit.
- smcameron 7y agoI use stgit for this kind of thing.
- Myrmornis 7y agoYes I think your workflow is more correct than using stash. Work that is fully intended to enter the branch should be in commits, not stashes.
- earthboundkid 7y agoYou can also use `git commit --amend` to clean up a WIP commit.
- inlined 7y agoI hate stash because it’s too easy to accidentally pop. I just use a lot of branches, get familiar with git rebase, and learn about git reflog in case I screw up.