gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 14:08:46 28 4
gpt4 key购买 nike

当我尝试提交时,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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com