Live data from Hacker News

Git: how to use stash

softwarecave.org

11–20 of 43 posts

Re: Git: how to use stash

#11

Does anyone know why stash names are so ugly? I've always found typing "git stash apply stash@{3}" to be pretty painful (not to mention redundant).

You might want to check out the Bash completions for Git: https://github.com/git/git/blob/master/contrib/completion/gi.... They work with stash names so can take some of the pain away.

Re: Git: how to use stash

#13
I never stash. I just commit instead and then rewrite my commit history with some reword/squash/fixup using git rebase -i. So in the end, it's like that half-commit never existed and I'm good to go. I've also found that people tend to forget about stashes. I can't count the times where I've found people with 3 or 4 months-old stashes swept under the rug.

Re: Git: how to use stash

#14
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"

Re: Git: how to use stash

#16

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"

Exactly 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".

Re: Git: how to use stash

#17
post #10

Does anyone know why stash names are so ugly? I've always found typing "git stash apply stash@{3}" to be pretty painful (not to mention redundant).

Making an alias to use something like `stash apply #3` shouldn't be too complicated

That's a bad idea, it would need quoting as the `#3` would be considered to be a comment in most shells.

Re: Git: how to use stash

#18
The most useful part was the comment:

> I think it’s worth emphasising that stash stores just your changes and not a snapshot of the entire tree. This means that you can create your stash on one branch and then pop it onto another branch. When you pop from the stash a merge is done including any conflict resolution that may be necessary.

Re: Git: how to use stash

#19
post #18

The most useful part was the comment: > I think it’s worth emphasising that stash stores just your changes and not a snapshot of the entire tree. This means that you can create your stash on one branch and then pop it onto another branch. When you pop from the stash a merge is done including any conflict resolution that may be necessary.

Is that any different from cherry-picking it from a branch?

Re: Git: how to use stash

#20

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"

Yes. 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.
Post reply on HN