Could not restore untracked files from stash

I lost all the files in my Xcode project after running git stash. Only ViewController and Main.storyboard left in the project which is empty. I tried all the solutions including git add ., git stash - u, git - save on the net but no solutions. Can anyone help me, please? Any solutions is very appreciated

Replies

Other info: When I run the command git stush, xcode asked me do I want to resave. I said yes

I made an experiment to a sample xcode project I created. I wrote a line of code. I used git stash(which is the command I used when I lost my xcode files in the first time) and after executing the command the code disappeared.I made a file and git stash again, lost the file.

I think this is an important tip.

Good news, I successfully recover the 'sample' one with git stash apply{stash1} but no help for the 'real' one.

I have three suggestions to help you. The first suggestion is to install Sourcetree, which is a free git app. Sourcetree shows your stashes in the sidebar of the repository window and provides a GUI to apply (restore) stashes. Using a GUI is generally easier than using the command line.


Second, move your question to the Continuous Integration and Source Control section of the forum. Your problem involves version control. You'll have a better chance of getting an answer there.


Third, you need to provide a lot more information for anyone to help you. Start by telling us how you created the git repository. Did you create it when you created the Xcode project or did you create the repository from the command line? Describe the changes you made to your project after creating the git repository. What files did you add to the project? What files did you change? Did you make any commits before you did the stash? List the exact git stash command you entered and the exact command you entered to apply (restore) the stash.

I will install Sourcetree

>Did you create it when you created the Xcode project or did you create the repository from the command line?

Yes, I created the Git reposity when I created the project.I added some Swift files, some View Controller and Table View Controller and Table View Cell and storyboard files.

> What files did you change?

What change do you mean. If writing code to it is considered as change, then I changed all files.

>Describe the changes you made to your project after creating the git repository.

Nothing just creating Podfiles, create some files writing the code.

>List the exact git stash command you entered and the exact command you entered to apply (restore) the stash.

git stash

git stash -u

git stash pop

git add .

git stash apply stash{1}

Anyone please help me?

If you open the repository for your project in Sourcetree and there are no stashes in the sidebar on the left side of the window, the stash is lost. Unless you backed up the project before you did the stash, all the work you stashed is lost and I don't know of any way for you to recover it.


I don't why, but it appears the stash was removed before you could apply it.


I can't help you recover your lost work, but I can suggest a better strategy for the future. Instead of stashing a large number of changes without committing any of the changes, create a new branch after creating your project. Work on your project from the new branch. When you add source code files and storyboard files to your project, commit them. When you add new code and it works, commit the code that works. Make frequent small commits to minimize any potential data loss.


The advantage of working off a new branch is you can work on your project without affecting any working code. If your new changes don't work, you can just delete the branch. If your new changes work, you can merge them into the master branch.

Fortunately, I found the stashes in the SourceTree and git stash apply stash{1} and get those files back.Thank you very much for the help and the SourceTree.


Before this thing happened(lost the files), I have same project but in different places(Mac screen and Finder). But the one in Finder is more complete, more code written, more files. After recovering the file, the recovered project is the one which is less complete(the one in Mac screen), but I want the project in the Finder. Do you know how to do that?

Double-click the Xcode project file that's in the Finder. Now you'll be working on the Finder project in Xcode.


If you somehow find the Finder version of the project isn't tracking version control changes, choose Source Control > Create Git Repositories to put the Finder version under version control. If you are using Xcode 8 or earlier, the menu item name is Create Working Copy instead of Create Git Repositories.

Thanks for that. I finally know what is going. I actually 'git stash' to this project a long ago. And I successfully get back the files. Now, I also recovered the files, but it's the files which are the ones before the first 'git stash' in the long time ago. Any suggestions?

I have 8 stash@{}s when I run the git stash list