Recovering files from Git objects

↘锁芯ラ 提交于 2019-11-28 03:47:12

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/6545232/recovering-files-from-git-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!