back

by pwim·15y ago·view on hn ↗
As far as I understand, git actually always keeps your changes. It is just the pointers that can be overridden if you force an update. For instance,

  git reflog show origin/master
shows even remote forced-updates. So although it looked like the commit was lost, it was still there, just not immediately visible, and was fully recoverable.
2 comments
Yeah, exactly. We (GitHub) use reflogs on the server, so everything that was pushed was in the repository and can't be gc'd out for at least 90 days. The master branch ref was just pointing at the wrong commit due to the forced pushes.
Reflogs are a lifesaving Git feature, but I imagine a large proportion of "casual" Git users don't know they exist, not least because a lot of people's Git education comes from poking around the GitHub interface.

It'd be amazing if GitHub began exposing reflogs through the web somehow.

You can lose commits if you use git gc but you're probably aware of what you're doing when you do that.
Even with git gc you have to try pretty hard to lose updates -- I believe by default it will leave stuff only reachable from the reflog around for 90 days.

(I <3 git.)