Helppi snippetit ja muut

Git: How to restore repository, from clone of it, that has all the version information intact. Step by step guide.

This method requires that you have shell access to the git-server of your cloned repository you want to save. 

 

Step 1: Gain access to git-server as git user. if you dont have such: then you can use any location you want for recreating the repository from wich you clone. just initialize the <somename>.git some where you have access to.

Step 2: re-create *.git directories that you want to restore. they should be bare initialized

mkdir <repository name>.git

cd <repository name>.git

git init –bare .

git symbolic-ref HEAD refs/heads/master

Step 3: clone the repository in question: git clone gitUser@gitServer:repo-name.git

Step 4: check the configuration from .git/config. what you need to check is that the git-server name and repository name is ok.

Step 5: check branch via git branch -a see is there main or master branch

Step 7: Local clone should be restored with: git reset –hard <branch name>

Step 8: Add all needed files with git add as normally would

Step 9: Make ’new’ commit with restored files, make some minor space change for example to make git to push items to server.

Step 10: just issue git push, and you should have restored the repository with all the version info etc.

Step 11: VERIFY that you are good to go by doing completely new clone from the repo you just restored with git clone <git uri> and see that it rocks BEFORE doing anything else.

Leave a Reply

Sähköpostiosoitettasi ei julkaista. Pakolliset kentät on merkitty *