top | item 4039230

(no title)

billybob | 13 years ago

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.

discuss

order

Xurinos|13 years ago

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.

davvid|13 years ago

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

billybob|13 years ago

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