News for hackers. Stuff that matters.
Re:Things I wish everyone knew about Git (Part I) by stu2b50 on Wednesday June 29, 2022 @06:14PM (#31926345)
You can git reset --hard and still get your work back without much trouble. Resets just move the branch pointer back, after all.
Re:Things I wish everyone knew about Git (Part I) by cryptonector on Wednesday June 29, 2022 @06:19PM (#31926391)
Hard resets throw away extant changes in the workspace that are not in the index or committed. You can't find those changes in the reflog or stash.
Re:Things I wish everyone knew about Git (Part I) by remram on Wednesday June 29, 2022 @09:04PM (#31927605)
It also throws away changes from both the working copy and the staging area.
Re:Things I wish everyone knew about Git (Part I) by cryptonector on Wednesday June 29, 2022 @10:31PM (#31928172)
Only if --hard is given.
Re:Things I wish everyone knew about Git (Part I) by remram on Thursday June 30, 2022 @09:59AM (#31932429)
Which is what we're talking about.
Re:Things I wish everyone knew about Git (Part I) by cryptonector on Thursday June 30, 2022 @10:19AM (#31932633)
Right, so stop typing that at all. Instead use `git checkout -f` to throw away extant changes. The `-f`/`--force` option is a lot clearer in intent than `--hard`.
Re:Things I wish everyone knew about Git (Part I) by remram on Thursday June 30, 2022 @02:02PM (#31936159)
The GP was talking about "moving the branch pointer", which checkout does not do. I am encouraging you (for the second time) to read the thread you are replying into...

git checkout can also nuke changes from both working copy and staging area. `git checkout <path>` will nuke working copy (and auto-completion is likely to give you a path when you were looking for a branch), `git checkout <ref> <path>` will nuke both. No --force required in either case, so let's not pretend that you can't lose changes without a scary-looking flag like --force or --hard.

Re:Things I wish everyone knew about Git (Part I) by cryptonector on Thursday June 30, 2022 @02:28PM (#31936526)
> The GP was talking about "moving the branch pointer",

Not explicitly.

`git checkout ref path` implies `--force`, since you're being specific.

I would prefer if Git could keep a GCed pile of saved workspace changes every time you force checkout/reset.

But for the love of all that is good, stop using `git checkout`/`git reset` in the few ways they hurt.