11

Git pull command is working fine, but git stash is giving the following error:

$git stash error: unable to resolve reference refs/stash: No such file or directory fatal: Cannot lock the ref 'refs/stash'. Cannot save the current status 

How do i resolve this so that i don't loose my changes?

7
  • Does your user have write permissions in the .git/.git/refs directory? Commented Aug 28, 2013 at 5:48
  • 1
    What OS and what git version are you using? Commented Aug 28, 2013 at 5:48
  • git version 1.7.9.5, Linux OS. .git and .git/refs have read and execute permissions Commented Aug 28, 2013 at 6:26
  • 1
    @schipitch: You must be able to write to the directory, otherwise you cannot create files Commented Aug 28, 2013 at 6:59
  • @knittl i have been using git for quite some time, and it has been working with the same permissions, it is only today that this error occurred. Commented Aug 28, 2013 at 9:45

4 Answers 4

23

I was having a very similar issue, after a corrupted filesystem.

The solution was to remove the file or directory at .git/logs/refs/stash

After deleting the file or directory, please use git stash to create a new ref, and that's all.

This will delete any stash you might have, so please be careful.

git stash error: refs/stash does not point to a valid object! rm -r .git/logs/refs/stash git stash Saved working directory and index state WIP on master: e1d74d8 fixing get_thumbnail_list 
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, i did similar thing, and this problem didn't arise again. Thanks
on git version 2.6.2 the file can be found at: .git/refs/stash
Where do the files/commits/objects live if you have multiple stashes on multiple branches? and multiple stashes sharing a single parent commit?
21

I had to delete following file also to get it working.

rm -f .git/refs/stash 

3 Comments

Computer crashed during git stash operation and seemingly I lost all my stashes. TL;DR: deleting only this bad .git/refs/stash allowed me to recover my stash list. In case it helps anyone else: My stash seemed ok in .git/logs/refs/stash (so didn't want to delete this). Followed first step of: dev.to/meduzen/recover-a-lost-git-stash-in-two-steps-569 where the git fsck command reported: error: refs/stash: invalid sha1 pointer 0000000000000000000000000000000000000000 error: bad ref for refs/stash but stopped here and did another search to find this SO answer :D.
Didn't work fully - seems like all it did was allow git stash list to return, but trying to run git stash apply doesn't work at all. warning: Log for ref refs/stash unexpectedly ended on Tue, 17 Dec 2019 22:27:25 +0900. Guess I have to abandon this repo and start again. Other git operations don't seem to work properly either.
I had to delete .git/refs/stash.lock as well. After that git stash started to work well.
2

You can remove the stash and add new stash folder if the problem still remained after remove the stash:

rm -r .git/logs/refs/stash

mkdir .git/logs/refs/stash

Comments

0

This is how I fixed mine. Had some funky stashed objects that were causing my problem. NOTE: Had to include the stash.lock in order to get it to work.

rm -r .git/logs/refs/stash .git/logs/refs/stash.lock 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.