从Git对象中恢复文件 [英] Recovering files from Git objects

查看:220
本文介绍了从Git对象中恢复文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我抹掉了我所有的工作,并且不愿意解释如何。
我留下的唯一东西是git对象。更多的是我想恢复一些损失包装的图像文件。从目标文件的大小我可以知道它们是哪一个。有没有办法将它们变回可用的文件? 第一件事:做一个备份!然后处理该备份的副本。

如果git对象仍在正确的目录中( .git / objects / xx / xxx ... )你可以使用 git fsck --full 来让git发现它们 - 它可能会列出存储库中的每个对象。现在查找标记为 commit 标记的标记,这些标记是您想要恢复的标记。



我可能会使用一个脚本为每个发现的提交对象创建一个分支(例如,简单地引入数字 rescue-1 rescue-2 等)。之后使用 gitk --all 来可视化所有分支并挑选最新的(最近的)分支。创建一个新的分支 rescued-master



签出您的新主分支并运行 git分支 - 无合并。你应该得到分支提交列表,不包含在master中。你可能想给他们一个新的分支名字。



完成后,删除所有编号为 rescue - 分行。



希望能够帮助并给出一个出发点。


I obliterated all my work and would prefer not to explain how.
The only thing I have left are the git objects. More then anything I would like to recover some of the loss packed Image files. From the size of the object files I can tell which ones they are. Is there a way to turn them back into usable files?

解决方案

first thing: make a backup! then work on a copy of that backup.

if the git objects are still in the correct directory (.git/objects/xx/xxx…) you can use git fsck --full for git to discover them — it will probably list every object in your repository. now look for the ones labeled commit and tag, those are the ones you want to recover.

i would probably use a script which creates a branch for each commit object found (e.g. simply increnting numbers rescue-1, rescue-2, etc.). afterwards use gitk --all to visualize all your branches and pick the top (most recent) one. create a new branch there rescued-master.

checkout your new master branch and run git branch --no-merge. you should get a list of branched off commits, not contained in master. you probably want to give them a new branch name too.

after you're done, delete all the numbered rescue- branches.

hope that helps and gives a a starting point.

这篇关于从Git对象中恢复文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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