GitHub Desktop for Mac deleted half of my project files. #23016
-
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! |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
@silver978 sorry to hear you are having trouble! The >Is because I reverted to an old version of my project (to an old commit)? Did you use the 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 (
Please share the output of that command. It should give a history of what happened in your repository. |
Beta Was this translation helpful? Give feedback.
-
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
Is it possible to recover the lost changes anyway? |
Beta Was this translation helpful? Give feedback.
-
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
This creates a Let me know if you run into any issues with this. |
Beta Was this translation helpful? Give feedback.
-
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! 😃 |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot. This solution has just recovered all my stuff that I was working on almost 2 years. But I’m still shaking. |
Beta Was this translation helpful? Give feedback.
-
Help me to recovery lost files |
Beta Was this translation helpful? Give feedback.
-
and you don't actually pile up commits, make them small even in our company here, it's a practice, make that as your practice too the tendency when there is a very big commits are losing the track, merge conflicts which you don't want to happen really as it can lose changes too, it's a nightmare, and unintended bugs since you are changing a lot and not noticing it's affecting other parts of the codebase too, just one mistake and you just ruined the entire codebase |
Beta Was this translation helpful? Give feedback.
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.