git/list[1] front-page[2] threads[3] people[4] search[5] about
 

making "git stash" safer to use

From
BHBruno Haible <bruno@clisp.org>
Date
Oct 3, 2007, 21:31 UTC
Message-ID
<200710032331.41385.bruno@clisp.org>
In-Reply-To
<47023699.3080606@byu.net>
Hi,
Through a simple typo I lost modifications to 20 files:
Show 5 quoted lines
> >>>     $ git stash
> >>>     $ git pull
> >>>     $ git stash apply
> >>>     $ git stash clean              # typo!
> >>>     $ git stash clear              # fatal correction to typo!
It is just too easy to lose your modifications by using "git stash".
Eric Blake further says:
> While we're at it, I wish 'git stash clear' would take an optional
> argument that says which stash(es) to clear, rather than blindly clearing
> the entire stash.

It would help if git would store which of the stashes were applied since they were created and which were not. A stash that was not yet applied must be considered "precious", whereas a stash that was applied is redundant, right?

According these lines, how about
  1) changing "git stash clear" to remove only the redundant stashes,
     (or alternatively: let it fail if there is at least one precious stash),
  2) adding an option -f, so that "git stash -f clear" clears all stashes,
     including the precious ones.

The rationale is that humans are bad at remembering the state of something. Therefore instead of having a command that is commonly used in one state and dangerous in the other state, better have two different commands - one for the common case, and one for the dangerous one. Like "rm" and "rm -f".

Bruno
Previous: Eric BlakeNext: Junio C Hamano
Message 2 of 15 in “Re: git: avoiding merges, rebasing”
  1. Eric BlakeOct 2, 2007
  2. making "git stash" safer to useBruno Haible, Oct 3, 2007
  3. Junio C HamanoOct 3, 2007
  4. Joachim B HagaOct 4, 2007
  5. David KastrupOct 4, 2007
  6. stash clear, was Re: git: avoiding merges, rebasingJohannes Schindelin, Oct 19, 2007
  7. Miles BaderOct 23, 2007
  8. Bruno HaibleOct 3, 2007
  9. Benoit SIGOUREOct 8, 2007
  10. Benoit SIGOUREOct 8, 2007
  11. Johannes SchindelinOct 9, 2007
  12. Benoit SIGOUREOct 9, 2007
  13. Bruno HaibleOct 9, 2007
  14. GNU-style ChangeLog merge driver for Git (was: Re: git: avoiding merges, rebasing)Benoit SIGOURE, Oct 9, 2007
  15. Bruno HaibleOct 9, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.