Get back lost shelf changes
Asked Answered
J

6

41

I have shelved my 26 java files changes via Intellij Idea 2016.2.1 and I checkout to different branch.

When I came to old branch to check my shelved changes.

I gone a mad now, I lost all the files. I was worked nearly two months

Can somebody help to get it back?

Jarred answered 20/9, 2016 at 8:11 Comment(2)
To be clear, are you saying the Unshelve Changes dialog does not show your files? Or that you cannot get to that dialog?Novellanovello
Yes, Unshelve Changes does not showing my files @NovellanovelloJarred
I
62

Even there isn't Shelf tab in IDE you can find shelved changes as patch files at:

{ProjectName}/.idea/.idea.{ProjectName}/shelf/.idea/shelf

Then your can apply any selected patch.

Implication answered 19/3, 2020 at 8:20 Comment(6)
Great life hack! You've saved couple hours of my work, thanks a lot!Awash
This is exactly what i needed! Life saver!Weathered
I had this issue after an Idea version upgrade. The issue was really just that the Shelf tab in the Commit pane was not visible. On the apply view for a patch there is an "Import to shelf" option. That action on any patch causes the shelf tab to re-appear - and all my previously shelved changes/commits were again visible. This way you don't even have to worry about which patch you apply.Mellen
Thank you. This just happened to me... I'm saved.Atencio
@Mellen Where is that apply-view or how do I get it? Andrej's answer is great, but how do I use the shelved.patch file besides manually (which get's a huge amount of work quickly)? Actually for me, the file was located a bit differently: {ProjectName}/.idea/shelf/{NameOfChangelist}{possibly incrementing count}Manzanilla
This is life saving. ThanksGilberte
C
32

You can restore the state of those files if they were edited in IntelliJ. Use local history to see all the changes made in IntelliJ (VCS -> Local History -> Show History).

Cyclohexane answered 20/9, 2016 at 20:43 Comment(2)
Genius :) Sometimes, it is necessary to think in another way. However, I have to remember which files I edited :( Update: I found that if the root folder's local history is examined, the files can be found, too.Pelasgian
As of 2020.3 use (File -> Local History -> Show History)Torrential
W
15

I was able to view lost changes and revert back to them by:

  1. right click on project directory, select Local History > Show History
  2. Find the entry in the history menu that you want to restore. You can examine the files by double clicking on the entry and the files to examine differences.
  3. Right click on the entry you want to restore, and select Revert

Note in my case Git>VCS Operations>Show History showed nothing. Only through the Project Files menu.

Whopper answered 10/12, 2020 at 20:25 Comment(0)
J
3

Andrei's answer was helpful for my situation where I renamed my project and my previously shelved changes were no longer found under the shelf, but I did run into an issue when applying the patch file because I was prompted to "Select missing base" for various files in the patch. Similar to what is seen in the screenshot below:

enter image description here https://youtrack.jetbrains.com/issue/IDEA-183910

I was able to avoid having to "Select missing base" for various files by first changing the default shelf location and then applying the patch.

enter image description here https://www.jetbrains.com/help/idea/shelving-and-unshelving-changes.html#change-shelve-location

Also, I found my patch in this location:

{ProjectName}/.idea/shelf

instead of the aforementioned location:

{ProjectName}/.idea/.idea.{ProjectName}/shelf/.idea/shelf
Jodijodie answered 27/4, 2022 at 15:18 Comment(1)
How do you apply a patch file? Link to Andrei's answer (unfortunately, the edit queue is full)Manzanilla
C
1

Maybe this will help someone: I lost part of my shelved changes in combination with an update of IntelliJ. I'm not sure if the update was the reason but eventually most of my most recent (and important) changes were gone. I couldn't restore them from local history as this does not "survive" an update of IDEA. But in the files I saw that there still is some data: C:\Users\myUser\AppData\Local\JetBrains\IntelliJIdea2021.2\LocalHistory had a changes.storageData with ~50MB. Copying the files to the folder of the new version didn't help as the files got overwritten again.

Solution: I was able to get the old version of IntelliJ (2021.2) here and installed it. This can be done in parallel, without removing the newer version. Here I was able to retrieve my changes from the Local History and shelve or apply them again.

Hint: Backup the "Local History" folder (or the whole IntelliJIdea20xx.x folder) before you start. I don't remember if I had to copy it in there again or if it worked out of the box. (Just to be sure the local history doesn't get lost).

Chromolithograph answered 4/8, 2022 at 14:15 Comment(0)
S
1

I've also experienced this bug repeatedly and hence no longer use shelved changes, but rather the Git CLI directly. As of 2022 Jetbrains IDE's still cannot be trusted with their "Smart Checkout" feature, which has a small probability of the total loss of your files (experienced personally in both IntelliJ & Rider).

Unlike another comment here regarding using the Local History, this did not work for me as the history showed nothing. I've also lost many hours of work due to this bug which remains unfixed.

The solution is to use "git stash -u" on the command line, then checkout the desired commit. Once youre done, type "git stash apply" to restore your files. Trusting the "smart checkout" feature is like playing Russian roullette. It's IDE magic that may just fail and you lose everything.

Skipjack answered 27/10, 2022 at 11:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.