开发者

Can I ever lose committed work, in git?

Is it ever possible to lose work in git? Let's assume all my work is committed, and I didn't run git gc. If I try some "funky command" ( NOT rm -rf .git ), and something strange happens to my project, could开发者_运维百科 I recover from it? Is there something in particular I should avoid doing? Or clone the repository elsewhere before attempting it?


Most errors you make with git can be recovered through the use of the reflog. One exception to this is deleting your branch, because of course that deletes the associated reflog. If that happens you may still be able to find the branch again by looking at the reflog of HEAD, but if you haven't checked the branch out in a while (or never checked out the latest tip of the branch) then it won't be there. But even then, you can try using git fsck --lost-found to find your dangling commits, and trawl through them to find likely candidates for the branch tip.

As you already indicated, if you run something which corrupts the .git directory, then all bets are off.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜