git - Github for Windows 崩溃后如何恢复存储库?

标签 git github github-for-windows

当我尝试提交时,Windows 版 Github 崩溃了,现在 git(命令行)告诉我每个文件都是新的。我还有一个 .get 文件夹,大小为 53mb。在此之前,我已经进行了大约 60 到 100 次提交。

如何在不丢失任何历史记录或更改的情况下恢复我的工作副本?

Git 状态说:

On branch master

Initial commit

Changes to be committed:
(use "git rm --cached ..." to unstage)

new file: .gitattributes
new file: .gitignore
... (1620 more files)

Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)

modified: Src/Foo/Bar/Index.cshtml

Untracked files:
(use "git add ..." to include in what will be committed)

Posh Git 命令提示符如下所示

C:\Projects\Foo [master +1623 ~0 -0 | +0 ~1 -0]>

git log输出如下

C:\Projects\Foo [master +1623 ~0 -0 | +1 ~1 -0 !]> git log
fatal: bad default revision 'HEAD'

更新

我刚从 Git GUI 运行“验证数据库”,结果如下:

dangling tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 dangling commit 30855e0deee8600f10733e6760db54fee2570a38 dangling commit cd8bc69ad56ca5c4d51d0d5028525698158cf3ec dangling commit c934f9823d907cd69c5e08a0159b9de4dfe3da35 dangling commit f958caca247978db978b70460276b5da7582bb06 notice: HEAD points to an unborn branch (master) notice: No default references

最佳答案

好的,首先,我复制了我的工作副本,所以我总是有一个后备位置。接下来,我运行了 git fsck,它给出了以下输出。

> dangling tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 dangling commit
> 30855e0deee8600f10733e6760db54fee2570a38 dangling commit
> cd8bc69ad56ca5c4d51d0d5028525698158cf3ec dangling commit
> c934f9823d907cd69c5e08a0159b9de4dfe3da35 dangling commit
> f958caca247978db978b70460276b5da7582bb06 notice: HEAD points to an
> unborn branch (master) notice: No default references

从这里开始,我使用了

git checkout <some-hash>

处理上面悬空提交的哈希值。事实证明,最后一个悬空提交是我最近的提交,所以 git checkout c934f9823d907cd69c5e08a0159b9de4dfe3da35 让我回到崩溃前的工作副本。

从这里我执行了 git checkout -b master,它在这次提交时重新创建了我的 master 分支。 git status 现在显示一个更改,这是我尝试进行的提交。致力于让我回到正轨。

关于git - Github for Windows 崩溃后如何恢复存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13001214/

相关文章:

git - 与 Visual Studio 存储库中的共享库

代理 : remote HEAD refers to nonexistent ref, 后面的 git 无法 checkout

Angular github 页面路径有重复的应用程序名称

git - 为什么 git(有时)在 merge 时克隆提交?

github - 在 GIT GUI 中生成新的 SSH key

git - 完全陷入 git - "git push"不工作, "git pull"不修复

javascript - 除了在开发期间进行测试之外,在登台服务器上进行测试还有哪些好处?

git - 如何撤消本地代表中的所有更改并使其克隆 github 中的上游

git - 删除在更改 git 提交作者详细信息时发生的重复提交

git - 使用 Github for Windows 发布到多个远程