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
To delete a particular stash from the available stashes, pass the stash id in stash drop command. It will be processed as: Syntax: $ git stash drop <stash id>
To undo a git stash , use the git stash pop command. It will re-apply your stash to your working copy.
git stash drop
takes no parameter - which drops the top stash - or a stash reference which looks like: stash@{n}
which n
nominates which stash to drop. You can't pass a commit id to git stash drop
.
git stash drop # drop top hash, stash@{0} git stash drop stash@{n} # drop specific stash - see git stash list
Dropping a stash will change the stash@{n}
designations of all stashes further down the stack.
I'm not sure why you think need to drop a stash because if you are using stash create
a stash entry isn't created for your "stash" so there isn't anything to drop.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With