28

I have been using PhpStorm and recently stashed a load of my changes. At some point after that, my PC profile became corrupt and had to be rebuilt.

Now that I have a new PC profile, PhpStorm is not showing my stashed changes.

Is there any way I can get them back?

Saurav Sahu
  • 13,038
  • 6
  • 64
  • 79
Typhoon101
  • 2,063
  • 8
  • 32
  • 49
  • 3
    Have you looked into the documentation? Stash is locally saved in `refs/stash`. Have you ever seen someone else' stash on your computer? I guess not. Have you ever tried pushing a stash? It's not possible. When your local repository clone is gone, your stashes are gone. – Daniel W. Nov 17 '16 at 11:24

3 Answers3

28

From the docs, the latest one is stored in ./.git/refs/stash while older ones are in the reflog of that ref.

As an aside, I've found it's a bad practice to maintain a regular use of git stash. Generally, prefer many small commits on a feature branch. This way you rarely have to stash and when you do it's very little stored as such. I generally stash only when I need to touch something away for a few minutes, and then apply when I'm done looking at something.

https://git-scm.com/docs/git-stash

Saurav Sahu
  • 13,038
  • 6
  • 64
  • 79
Paul
  • 35,689
  • 11
  • 93
  • 122
16

The actual data stashed by "git stash" (i.e. the current version of the working tree and the contents of .git/index) is stored as two commit trees.

One commit tree contains a snapshot of the current state of the working tree. There are some tricky bits here, see below.

The other commit tree, I've been told, is used to store a snapshot of the contents of .git/index at the time of the stash. I haven't looked into this deeply enough (yet) to understand how the one is translated into the other.

.git/refs/stash contains the hash value for the commit tree that the stash created.

.git/logs/refs/stash contains a reflog-like chunk of metadata about the stashes before the one in .git/refs/stash.

.git/index holds a list of entries for each file in the working tree. Those entries contain the full path and filename and also cached metadata about the file, both filesystem metadata and git-related metadata.

"git add" both add a copy of a file to the object store, and sets the staging flag for that file in .git/index.

For "git stash" to create a commit tree, files that have been changed (edited) but not yet staged with "git add" have to be added to the object store. "git stash" does this by building a temporary index file.

Audwin Oyong
  • 2,247
  • 3
  • 15
  • 32
Steven J Owens
  • 809
  • 8
  • 9
  • 2
    I don't have a `.git/refs/stash` file on my Mac running Git 2.22, but I do have them all listed in `.git/logs/refs/stash`. – Tamlyn Jun 17 '20 at 10:39
  • 1
    @Tamlyn A non-existing `.git/refs/stash` means that you currently have nothing on the stash: `git stash list` would not show anything for you. The fact that its reflog exists shows that you once stashed something, but you must have dropped or popped it. – Eph Dec 11 '20 at 13:41
6

All are stored in .git/refs/stash. git stash saves stashes indefinitely, and all of them are listed by git stash list.

Please note that dropping or clearing the stash will remove it from the stash list, but you might still have unpruned nodes with the right data lying around.

Shravan40
  • 8,922
  • 6
  • 28
  • 48