Mike
Mike

Reputation: 41

Restoring from git when local directory is gone

Ok this is going to get complicated:

My .git directory is in a different directory than the source files. You can actually do that with:

/usr/local/bin/git --git-dir /www/git/site/ --work-tree=. commit -a 

(when you're in the directory of the source files. Unconventional, but that's how we do it, and it's supported).

The directory with the source files has been deleted.

But the .git repository hasn't, because it's in a separate directory. I can see it, I know where it is.

How do I restore everything from our latest commit into a new directory? I tried this in a new directory:

/usr/local/bin/git --git-dir /www/git/site/ --work-tree=. pull 

gives:

fatal: No remote repository specified. Please, specify either a URL or a remote name from which new revisions should be fetched.

(fyi there's no remote server, this is all local)

Upvotes: 2

Views: 64

Answers (1)

mkrufky
mkrufky

Reputation: 3398

After creating a new directory, change into that directory. Then, you can restore the entire tree with the following command:

/usr/local/bin/git --git-dir /www/git/site/ --work-tree=. reset --hard

if that doesnt work, try adding .git to the location:

/usr/local/bin/git --git-dir /www/git/site/.git/ --work-tree=. reset --hard

Upvotes: 1

Related Questions