Reputation: 11
I Accidentally deleted .git/objects folder. I have had commits that haven't been pushed to the remote yet so i'm worried that some changes are lost. What can i do now to restore them?
Upvotes: 0
Views: 99
Reputation: 170
If you cannot restore the folder like C1sc0 suggested, a fairly simple solution would be to just clone the git project into a new directory, then compare the folder where you deleted the .git folder with the folder you just cloned the git project inside. Some IDEs have a very good compare function that makes this quite easy. Then just paste the changes over, commit and push. After you are sure everything works, you can delete the folder where you deleted the .git folder from, as the new one should have all your changes.
Upvotes: 1
Reputation: 30277
If it has been deleted, like for real..... not much git can do here. You will need to do some work to be able to resume work, but forget about the revisions you had created locally. So... clone a second repo from the original repo that you started working from (assuming you are working as people normally do these days using a central repo to work against).
When you have that, create a branch (what will be your branch from now on) on the latest revision that you were able to merge from the upstream branch in the original repo (assuming it's not the tip of the upstream branch.... but it could be the tip).... or, if you never merged, then set the branch at the same commit where your branch was started from.
Checkout that branch and now replace the working tree with what you have in the working tree of the broken repo (do not bring anything from git's database).... now you can resume working on that branch.
By the way, I am making a bunch of assumptions:
And there could be others that my subconscious me is hiding from me to make my life simpler.
Upvotes: 1
Reputation: 2984
If you are on windows you can restore it from the recycle bin. (And similarly on linux from Trash) (except if you deleted with shift+delete)
Upvotes: 0