问题
Due to some error in code, we lost a complete GIT-controlled directory. Restoring the files was not a problem; TimeMachine took care of that. However, TimeMachine apparently did not back up the .git folder.
Is there a better way to restore/recreate the .git folder than to fetch the directory from the master server or another machine?
Thanks in advance for any useful hint.
回答1:
You can check out a bare .git repo and then inflate it into a full repo by adding your source code. This will still download the entire .git folder but not your working copy code files.
- Create a new folder and navigate to it.
Clone a bare repo:
git clone --bare https://path/to/project .git
Copy your locally recovered files around the .git folder (in the same relative location as they were earlier).
Mark the new repo as non-bare:
git config --local --bool core.bare false
Finally reset the index:
git reset HEAD -- .
回答2:
There are 2 options:
1. restore it form backup (which i assume you don't have)
2. clone the repository again and compare the content to add the modified content.
Since .git is simply folder with content.
If you did not backup it with Time Machine so you will have to clone it again.
来源:https://stackoverflow.com/questions/24775326/best-way-to-restore-git-folder