Igor Igor - 1 year ago 75
Git Question

How to restore the project if I have only .git folder?

How to restore my project? I save only /.git folder and now need to restore project from this folder.

Answer Source

1. If you previously committed files to git:

First, try to do a git log. Then you will see the commits. If you see a commit that makes sense, you can do git checkout <HASH>. Where Hash is the commit hash.

Then check to see if yours files exits.

2. If it is only local changes that you have not committed:

You can do a git status to see the changes. A git stash will stash these changes temporarily and a git stash pop will re-apply the changes.


You can do a git reset --HARD <HASH> and then a git push -f to force push the working code up to your repo eliminating your mistaken commit but also eliminating all other commits after the hash.

It is much better to git revert <HASH> and then a git push. This will show the reverting process in your git history and preserve all states. git push -f is not something you should take lightly as it can cause you much pain.