从 Git 对象恢复文件
我抹掉了我所有的工作,并且不想解释是如何做到的。
我唯一剩下的就是 git 对象。更重要的是,我想恢复一些丢失的打包图像文件。从目标文件的大小我可以知道它们是哪些。有没有办法将它们转回可用的文件?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一件事:做好备份!然后处理该备份的副本。
如果 git 对象仍然在正确的目录中 (
.git/objects/xx/xxx...
),你可以使用git fsck --full
让 git 发现它们 - 它可能会列出存储库中的每个对象。现在查找标记为commit
和tag
的内容,这些是您要恢复的内容。我可能会使用一个脚本,为找到的每个提交对象创建一个分支(例如,简单地增加数字
rescue-1
、rescue-2
等)。然后使用 gitk --all 可视化所有分支并选择顶部(最新的)分支。在那里创建一个新分支rescued-master。签出新的主分支并运行 gitbranch --no-merge 。你应该得到一个分支提交的列表,不包含在 master 中。您可能也想给他们一个新的分支名称。
完成后,删除所有编号的
rescue-
分支。希望能有所帮助并提供一个起点。
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 usegit fsck --full
for git to discover them — it will probably list every object in your repository. now look for the ones labeledcommit
andtag
, 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 usegitk --all
to visualize all your branches and pick the top (most recent) one. create a new branch thererescued-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.