How to delete a stash created with git stash create?

Paul Wagland

Git stash seems to do a lot of what I want, except that it is a little hard to script, as the if you have no changes, then git stash; git stash pop will do something different than if you do have changes in your repository.

It appears that git stash create is the answer to that problem, and everything works, except for one thing… I can't get rid of the created stash. Is there any way to get rid of the stash?

To make it 100% clear what I am doing:

Create the stash:

~/tmp/a(master) $ git stash create 
60629375d0eb12348f9d31933dd348ad0f038435
~/tmp/a(master) $ git st
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   b
#
~/tmp/a(master) $ git reset --hard
HEAD is now at 555d572 log message

Use the stash:

~/tmp/a(master) $ git apply 60629375d0eb12348f9d31933dd348ad0f038435
fatal: can't open patch '60629375d0eb12348f9d31933dd348ad0f038435': No such file or directory
~/tmp/a(master) $ git stash apply 60629375d0eb12348f9d31933dd348ad0f038435
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   b
#

Delete the stash: (except that this last bit doesn't work)

~/tmp/a(master) $ git stash drop !$
git stash drop 60629375d0eb12348f9d31933dd348ad0f038435
'60629375d0eb12348f9d31933dd348ad0f038435' is not a stash reference
dahlbyk

To delete a normal stash created with git stash , you want git stash drop or git stash drop stash@{n}. See below for more details.


You don't need to delete a stash created with git stash create. From the docs:

Create a stash entry (which is a regular commit object) and return its object name, without storing it anywhere in the ref namespace. This is intended to be useful for scripts. It is probably not the command you want to use; see "save" above.

Since nothing references the stash commit, it will get garbage collected eventually.


A stash created with git stash or git stash save is saved to refs/stash, and can be deleted with git stash drop. As with all Git objects, the actual stash contents aren't deleted from your computer until a gc prunes those objects after they expire (default is 2 weeks later).

Older stashes are saved in the refs/stash reflog (try cat .git/logs/refs/stash), and can be deleted with git stash drop stash@{n}, where n is the number shown by git stash list.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to git stash pop the last stash created on current branch?

From Dev

Applying a git stash created with --all

From Dev

Applying a git stash created with --all

From Java

How to Git stash pop specific stash in 1.8.3?

From Dev

Git: How to get stash before the last stash?

From Dev

Git stash possible to apply stash created by another user?

From Dev

What is the purpose of git stash create and git stash store?

From Dev

How to delete stash by commit sha

From Dev

How can I create a GIT Stash from a Commit?

From Dev

How can I create a GIT Stash from a Commit?

From Java

How to recover a dropped stash in Git?

From Dev

How to undo git stash clear

From Dev

git stash reporting: '' is not a stash reference

From Dev

Do I need to delete my git stash?

From Dev

How to list the parent commit of a stash in `git stash list`

From Dev

Git: how to use stash -p to stash specific files?

From Java

How can I rename a git stash?

From Java

How can I git stash a specific file?

From Dev

how to move git commits to and from the stash?

From Dev

How do I undo a partial git stash?

From Dev

How to recover from "git stash save --all"?

From Dev

How to git fetch by branch creator from stash

From Dev

GitPython -- How to 'git stash' changes to a GitPython repository?

From Dev

How to git stash only untracked files?

From Dev

How can I share a git stash?

From Dev

Git - how to stash away a conflict and resolve it later

From Dev

git create stash without need to configure user.email and user.name (git stash --author ?)

From Dev

How do i update my code base in git without having to delete, stash or checkin my current changes?

From Dev

No stash found when using git stash branch

Related Related

HotTag

Archive