Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 6

GitHub Desktop for Mac deleted half of my project files.

Solved! Go to Solution.

Good morning,

 

I am a beginner with Git and I am learning by using it for a project.

I use GitHub Desktop for Mac.

I recently committed some changes of my project, but I wanted to revert the commit with the purpose of removing the virtual commit but not the real files (so I would edit the project and generate a new commit).

So, I clicked the Undo button and I deleted the latest commit, but also all my files.

The file loss is big, but I mentally went through it in order to resolve the problem of my project in a better way.

The purpose of this post is: why the Undo removed also all my files? Is because I reverted to an old version of my project (to an old commit)? If so, how can I remove a virtual commit without deleting all my progress?

Probably I'll switch directly to the console commands in order to have full control on my repo.

 

Thanks in advance!

 

5 Replies
Highlighted
GitHub Staff
Message 2 of 6

Re: GitHub Desktop for Mac deleted half of my project files.

@Silver978 sorry to hear you are having trouble! The `Undo` button in GitHub Desktop does not delete your files -- it undoes the commit and then leaves the files associated with that commit as uncommitted changes in your working directory.

 

>Is because I reverted to an old version of my project (to an old commit)?

 

Did you use the `revert` function in GitHub Desktop, or something else? If you attempt to revert to a previous commit with uncommitted changes in your working directory GitHub Desktop will throw an error, since you could lose those uncommitted changes.

 

The good news is that since you previously committed those files we should be able to recover any lost changes. Could you open up the command line (`Repository` > `Open in <your_command_line_application>`) and run the following command?

 

`git reflog`

 

Please share the output of that command. It should give a history of what happened in your repository.

Copilot Lvl 2
Message 3 of 6

Re: GitHub Desktop for Mac deleted half of my project files.

Thank you for your fast support!

 

As I see from the log, I used the revert function but without knowing much of it, my fault.

 

This is the output of the `git reflog` command:

6e880ec (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: reset: moving to 6e880ec2f19f35f5118d2eb693d0a14f68c32f47
d6c3e83 HEAD@{1}: reset: moving to d6c3e837bd7843fcdc778bcd1873b190fbc82a43
ef3f2c0 HEAD@{2}: revert: Revert "Added Map1 + Added collisions for Map1"
d6c3e83 HEAD@{3}: commit: Added Map1 + Added collisions for Map1
6e880ec (HEAD -> master, origin/master, origin/HEAD) HEAD@{4}: commit: Alpha logo intro
d1a3886 HEAD@{5}: pull --progress origin: Fast-forward
f9f9294 HEAD@{6}: commit: Game juice in progress
576ee4e HEAD@{7}: commit: Prototype in progress
ac7d772 HEAD@{8}: clone: from https://github.com/Silver978/egUnityRepo.git

Is it possible to recover the lost changes anyway?

Solution
GitHub Staff
Message 4 of 6

Re: GitHub Desktop for Mac deleted half of my project files.

What you can do is create a temporary recovery branch off of the commit you made prior to reverting your changes. You can then merge that recovery branch into your `master` branch once you have verified that everything is correct. Here's how to do that using the command line:

 

`git checkout -b recovery d6c3e83`

 

This creates a `recovery` branch off of the SHA of your previous commit. You should see this branch in GitHub Desktop after running that command.

 

Let me know if you run into any issues with this.

Copilot Lvl 2
Message 5 of 6

Re: GitHub Desktop for Mac deleted half of my project files.

You are my savior, really, thank you so much!

 

The new branch "recovery" has the correct project version I had before the revert: problem solved!

 

So, the files of the old commits are stored in some local folders (some sort of "backup", "recovery" folders)? Because I didn't push that commit.

 

I ask this only to understand what I did and how git works: if this is something already explained completely in the docs I'll go straight to study it.

 

Thank you again and have a nice day! :D

GitHub Staff
Message 6 of 6

Re: GitHub Desktop for Mac deleted half of my project files.

I'm glad to hear you were able to recover your files!

 

>So, the files of the old commits are stored in some local folders (some sort of "backup", "recovery" folders)? Because I didn't push that commit.

 

Think of a commit as a snapshot of the current state of your files that is stored in a database. Even if you make changes or delete those files from your local filesystem, that snapshot is still stored in the database, which means you can recover those changes at any time. 

 

If you are interested in learning more I'd highly recommend this section of the book Pro Git.