Hacker News new | past | comments | ask | show | jobs | submit login

I've been using Git for a couple years now, and I don't think I've ever lost any work.

Even if you do `git reset --hard HEAD~5`, "throwing away" your last few commits, they aren't actually discarded yet. You can do `git reflog` to see them and then `git checkout -b some_commit_hash` to recover one to a branch, or `git reset --hard some_commit-hash` to set this branch back to that point.

Only if those commits stay orphaned for a while (a week or two?) will Git truly discard them.




It becomes dangerous if you have changes in your working tree. You truly lose those changes with a "git reset --hard HEAD" or the forced checkout.


Exactly. As mentioned in the article, `git reset --keep` is the preferred way to do it these days. It preserves uncommitted worktree changes.


Oh! I see. I would never do a `git reset` of any kind if I hadn't committed or stashed. Yikes!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: