我可以在git中签出树对象吗? [英] Can I checkout a tree object in git?

查看:65
本文介绍了我可以在git中签出树对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在损坏的存储库中丢失了提交对象,但是仍然有一些文件和树对象:

I have lost the commit object in a corrupt repository, but there are still some files and the tree object:

$ git fsck                                                
Checking object directories: 100% (256/256), done.
dangling blob 031be26142ed97da216fb7d79d16a0b0efdf0d71
dangling blob 4b2be7dfef082c2e247be52e6d78600af7b6dd40
dangling tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
dangling blob ccbb1056cb4e744f9a4b44a439fa036f6a3d7cbe
dangling blob 10bfbc3c1fa10e08cd6a783565f00e7324f61fe5
dangling blob 9b529957be714fef304c4e8161fe6cd138510e98
dangling blob dd5b54882d0b74db99c8a7fbba703d528dc559b9

有没有办法检出那个树对象?

Is there a way to check out that tree object?

我想可能有一种方法可以用伪提交字符串重建提交对象,并检查出来.

I guess there could be a way to rebuild the commit object with a dummy commit string and check that out.

git cat-file -p tree-sha1

推荐答案

如果这种情况经常发生,或者您需要在其他提交之间来回切换,则可以创建一个指向该树的新提交对象,并且然后为方便起见,创建一个指向它的新分支:

If this happens often, or if you will need to switch back and forth from other commits, you can create a new commit object that points to this tree, and then create a new branch that points to it for convenience:

git commit-tree <<treeid>>
<<type a commit message>>
^D
<<this will produce a hash for the new commit object>>
git branch newbranch <<newcommithash>>

然后,只要需要,您就应该可以只git checkout newbranch ...

Then you should be able to just git checkout newbranch whenever you need to...

这篇关于我可以在git中签出树对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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