31

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?

Vojtech Ruzicka
  • 16,384
  • 15
  • 63
  • 66
Sanjay Dutt
  • 1,173
  • 4
  • 15
  • 19

6 Answers6

37

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.

Andrei
  • 749
  • 6
  • 7
  • 4
    Great life hack! You've saved couple hours of my work, thanks a lot! – mulya Oct 08 '20 at 06:20
  • This is exactly what i needed! Life saver! – Alex Vulchev Feb 14 '22 at 12:08
  • 1
    you saved one life today. – 最白目 Nov 09 '22 at 08:49
  • 1
    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. – user598656 Feb 21 '23 at 15:54
  • Thank you. This just happened to me... I'm saved. – gatoWololo May 09 '23 at 21:38
29

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).

tcb
  • 2,745
  • 21
  • 20
  • 3
    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. – Onur Demir Mar 13 '19 at 06:35
  • 3
    As of 2020.3 use (File -> Local History -> Show History) – Stephen Burke Dec 15 '20 at 14:33
11

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.

cnash
  • 564
  • 1
  • 7
  • 14
2

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
Josh
  • 91
  • 5
0

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).

Zaphoid
  • 2,360
  • 1
  • 18
  • 19
0

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.

user4779
  • 645
  • 5
  • 14