错误的.git文件夹

时间:2018-06-05 09:37:11

标签: git bitbucket

我正在设置一个新的开发服务器,同时切断前代理机构的访问权限。这包括建立一个新的回购并摆脱他们的。 所以我使用rsync将文件从实时服务器复制到开发服务器。然后我删除了.git文件夹,创建了一个新的repo并将其设置为推送到那里。在此期间,对实时服务器进行了一些更改,因此我决定再次进行rsync。我完全忘记了.git文件夹,一旦我意识到,我就取消了rsync,但是我太迟了,它将旧的仓库中的一些.git复制到了创建的新仓库中。现在我收到错误,如下所示。

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

我可以以某种方式恢复.git文件夹,还是需要重新创建?

由于

1 个答案:

答案 0 :(得分:1)

假设您已将新的repo推送到远程,解决此问题的最安全方法是将 new repo 克隆到新的本地目录中并进行设置使用具有损坏的.git目录的工作树。

这是一个循序渐进的指南:

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.

```

这里有一些关于more information选项的--work-tree

相关问题