Reputation: 321
I'm setting up a new dev server and, at the same time, cutting out access for a former agency. This includes setting up a new repo and getting rid of theirs. So I used rsync to copy files from the live server to a dev one. I then deleted the .git folder, created a new repo and set it up to push there. During this time there were some changes done to the live server so I decided to rsync once more. I completely forgot about the .git folder and I cancelled the rsync as soon as I realized, but I was too late and it copied some of the .git from the old repo to the new one that was created. Now I'm getting errors, listed below.
warning: reflog of 'refs/remotes/origin/snagging-882' references pruned commits
warning: reflog of 'refs/remotes/origin/snagging-896' references pruned commits
warning: reflog of 'refs/remotes/origin/snagging-899' references pruned commits
warning: reflog of 'refs/remotes/origin/snagging-911' references pruned commits
warning: reflog of 'refs/remotes/origin/develop' references pruned commits
warning: reflog of 'refs/remotes/origin/staging' references pruned commits
warning: reflog of 'refs/remotes/origin/review' references pruned commits
error: Could not read c1fd5ccb43ddea672fa5b141a0fdb0d65d813b8a
fatal: Failed to traverse parents of commit 57c5f1c268a7775ebab6ee4f42d94dec2159844f
error: failed to run repack
Can I restore my .git folder somehow or do I need to create again?
Thanks
Upvotes: 1
Views: 65
Reputation: 59915
Assuming you have pushed the new repo to a remote, the safest way to solve this problem is to clone the new repo into a new local directory and set it up to use the working tree from the one with the corrupted .git
directory.
Here's a step-by-step guide:
1. git clone <url-to-new-repo> FreshNewRepo && cd FreshNewRepo
# Clone the new repo into a new local directory called 'FreshNewRepo'
2. git --work-tree=/path/to/corrupted-repo add -A
# Set up the 'FreshNewRepo' to use the working tree from the corrupted repo
# (thereby getting the rsynced files from the old repo), then stage all changes
3. git status
# At this point, you should have all the changes from corrupted repo
# in the index of your 'FreshNewRepo'
4. git commit
# Create a commit to mark that you imported the latest changes from the old repo.
5. (optional) rm -rf /path/to/corrupted-repo
# Once you're certain that no changes are left behind in the corrupted repo,
# (either commits not being pushed or uncommitted changes in the working tree)
# there's no reason to keep it around.
```
Here's some more information about the --work-tree
option.
Upvotes: 1