3 ms·
Far better: git commit -a -m 'Work in progress' Switch to other branch, do work on it. When you come back to the branch, git reset --soft HEAD^ It's far les
by oneandoneis2 13y ago
Far better:
git commit -a -m 'Work in progress'
Switch to other branch, do work on it. When you come back to the branch,
git reset --soft HEAD^
It's far less volatile than stash, and far better at keeping WIP in the right place when things get so hectic that you have abandoned work on more than one branch.
Stash is only really safe to use for very short-lived uses, such as "stash/pull/unstash"
- foreigner 13y agoExactly right. When you first start using Git "stash" is a revelation, but over time you use it less and less. A good rule of thumb is "When in doubt, commit.". And embrace "rebase".
- Myrmornis 13y agoYes. One example use case for stash is saving some debugging change that makes sense being applied in many branches. But yes, most articles like this seem to be written by people who are yet to fully appreciate that branches are cheap/free.
- adwf 13y agoI think it's because some workplaces have policies about not committing partially done code. ie. Don't break the build. Personally, if I'm on a local branch I don't care, but I guess it might bother some people.
- pornel 13y agoIn git commits are done off-line, so nobody will see the commit if you don't push it. You can clean up such work-in-progress commits before pushing by using interactive rebase.
- taeric 13y agoHow is this really any better/different than just giving a message to a stash?
- peterwwillis 13y agohow many times have you stashed, and in what stages of development, and when you try to apply them later, will they be in order and will they work on the codebase as it has changed? also, do you even remember you stashed, and is there a log longer than 1 line? stash is a quick hack, and is useful as a quick hack, but commits just work better.
- taeric 13y agoStill no different than branches you forget to go back to. If you want the exact same behavior, than instead of stash apply use stash branch PickingBackUpStash That said, the majority of my uses of stash are "git stash; git pull; git stash apply" Or, alternatively, "git stash --keep-index; build; test; commit; git stash pop" The whole point is I am not leaving the stash for long. If I have left a stash dormant for some time, I likely just drop it. Similar with branches.
- fr0sty 13y agoWhy would you recommend reset --soft ? To get back to where you started (changes not added to the index, since you are doing commit -a) you should do `git reset --mixed HEAD~` (or drop the --mixed argument as it's the default).