在Git中,如何恢复在提交之前恢复的分阶段文件? [英] In Git, how can I recover a staged file that was reverted prior to committing?

查看:120
本文介绍了在Git中,如何恢复在提交之前恢复的分阶段文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Git Tower将更改导入我的存储库。当我这样做的时候,发生了冲突,我错误地把所有的事情都打到了舞台上(正如我在解决冲突后想要做的那样)。当我这样做时,冲突标记为已解决。



我想手动解决更改,所以我点击Abort Merge,但是,当我这样做时,它回滚我所有的变化!有什么方法让他们回来?

解决方案

如果你有任何东西上演混帐,你可能应该能够得到背部。 (如果您刚更改了工作副本,则无法恢复。)



首先:不是运行 git gc 。在继续之前备份您的存储库和工作副本。 (确保备份 .git 目录。)还要避免关闭发生这种情况的终端,和/或重新启动 - 如果全部失败,您有机会在历史记录/内存。



无论如何,首先要尝试的是:


$ b git fsck - -lost-found

它会打印一些类似于

 
检查对象目录:100%(256/256),完成。
检查对象:100%(30165/30165),完成。
dangling blob 8f72c7d79f964b8279da93ca8c05bd685e892756
dangling commit 4993502a6394491190d3f4d6fb3d1e14019c2e9b

由于您丢失了暂存文件并且没有进行提交,重新对 dangling blob 条目感兴趣。



运行 git show< sha> 为每一个 - 其中一些应该是你的文件。


I was attempting to pull a change into my repository using Git Tower. When I did so, there was a conflict and I mistakenly hit stage all (as I wanted to commit after resolving the conflict). When I did so, the conflict marked itself as resolved.

I wanted to manually resolve the change so I hit "Abort Merge", however, when I did this, It rolled back all my changes! Is there any way to get them back?

解决方案

If you had anything staged to git, you probably should be able to get that back. (If you just changed working copy, you wouldn't be able to restore it.)

First of all: do not run git gc. Backup your repository and working copy before going ahead. (Make sure to backup .git directory.) Also avoid closing terminal where this happened, and/or rebooting — if all fails, you have a chance to find stuff in history / memory.

Anyway, first thing to try is:

git fsck --lost-found

It will print something like

Checking object directories: 100% (256/256), done.
Checking objects: 100% (30165/30165), done.
dangling blob 8f72c7d79f964b8279da93ca8c05bd685e892756
dangling commit 4993502a6394491190d3f4d6fb3d1e14019c2e9b

Since you lost staged files and did not do a commit, you're interested in dangling blob entries.

Run git show <sha> for each one — some of them should be your files.

这篇关于在Git中,如何恢复在提交之前恢复的分阶段文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆