Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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

like image 275
Igor Avatar asked Jul 30 '16 16:07

Igor


1 Answers

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.

NOTE: THE FOLLOWING IS A DESTRUCTIVE GIT PROCESS BUYER BEWARE

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.

like image 91
joncodo Avatar answered Oct 23 '22 00:10

joncodo