Recovering files from Git objects

断了今生、忘了曾经 提交于 2019-11-29 10:43:13

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.

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