开发者

Can I ever lose committed work, in git?

开发者 https://www.devze.com 2023-04-01 03:43 出处:网络
Is it ever possible to lose work in git? Let\'s assume all my work is committed, and I didn\'t run git gc.

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

精彩评论

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

关注公众号