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?
Is it ever possible to lose work in git? Let’s assume all my work
Share
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-foundto 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
.gitdirectory, then all bets are off.