Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 views
in Technique[技术] by (71.8m points)

data recovery - Recovering Git repository from objects only

I have a Windows box which has taken it into it's head to delete most of a Git repository (must have tripped the Important Work Detector ;). All I have left (that I can find) is the objects. I'm not sure how complete the collection of objects is, either. Is it possible to recover things from just the objects? As far as I can tell, the object tree is intact. All the packs and loose objects are in place; I just don't have the metadata to convince Git.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The first thing that I would try is to initialize a new repository with git init. Then I'd copy the objects directory from the dead repository into the new repository. Then I'd run git fsck in the new repository.

With some luck you'll see a whole lot of dangling objects and with a bit more luck some of the dangling objects will be commit objects which will be the tips of lost branches.

If you run git show and/or git log on these commits you may be able to recognize some of the branches.

To "recover" them you can just use git branch to recreate named branches.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...