0 votes
1 view
in Devops and Agile by (20k points)

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

1 Answer

0 votes
by (28.4k points)

In order to delete a normal stash created with git stash, you want git stash drop or git stash drop [email protected]{n}. See below for more details.

When you create a stash with git stash or git stash save, it gets saved to refs/stash, and then can be deleted with git stash drop. Just like 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).

Also remember that older stashes are saved in the refs/stash reflog (try cat .git/logs/refs/stash), and can be deleted with git stash drop [email protected]{n}, where n is the number shown by git stash list.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...