3 ms·
git add . git commit -m "wip" when you're back git reset HEAD^ Keeps working changes nice and tidy in the branch they belong to, you can push them, a
by ricardobeat 6y ago
git add .
git commit -m "wip"
when you're back
git reset HEAD^
Keeps working changes nice and tidy in the branch they belong to, you can push them, and they are easily recoverable from the ref log, unlike stashes.
Also, god help you when a stash fails to apply.
- FreeFull 6y agoAlternatively, instead of `git reset HEAD^` you could do `git commit --amend` to merge further changes into the latest commit
- IggleSniggle 6y agoI needed this comment today. I am an avid stasher, despite knowing the downsides. It’s just so convenient (until it’s not...at which point I usually give up and trash it, and yell at myself for not settling into a partial commit sooner). But this workflow (which seems so very obvious in retrospect), keeps my current workflow, with so many benefits. The only place where it even requires extra steps is when you want to apply the stash to a different branch, and even there, it just feels right: “Oh yeah, I was working on that feature over there, let’s pop it off and go put it on this feature over here.” Since this generally requires careful diffing anyway to make sure things end up in the right place, there’s not much lost here, and without the downsides of stash.
- bradstewart 6y agoThis. I have these aliased as `git save` and `git unsave`, which makes it as convenient as `git stash`.
- bitjson 6y agoIf anyone is interested, there's a tiny utility I've used daily for years to do this: https://github.com/bitjson/wip https://github.com/bitjson/wip Each time you run `wip`, all current work is committed. When you run the squashing utility `naenae` (autocomplete: `nae + Tab`), the most recent line of "WIP" commits is saved to a `wip-archives/[branch]/[timestamp]` branch for safe keeping, the commits are all squashed in place, and you're left in your default git editor to define the commit message. It also handles unusual situations, like using `wip` for the first commit (in which case, `git reset HEAD^` will return an error). Being able to set a sort of "WIP checkpoint" in the current working directory makes it really easy to start or back out of big changes, and it can be very useful to check back in past WIP commits to grab segments of code you previously threw away.
- corytheboyd 6y agoI do this all the time, it’s the only real way of saving state when you are abruptly asked to do something else