Hacker News new | ask | show | jobs
by fileeditview 2596 days ago
Wow just tried this.. is this considered a bug or a feature and where can you read about this if it is intended behavior?
2 comments

`git checkout --help` gives

       git checkout [<tree-ish>] [--] <pathspec>...
           Overwrite paths in the working tree by replacing with the contents
           in the index or in the <tree-ish> (most often a commit). When a
           <tree-ish> is given, the paths that match the <pathspec> are
           updated both in the index and in the working tree.
As 'widget' is a path (and not a branchname as most often), local changes will be overwritten. Together with `git reset --hard` this is a bit a dangerous operation. I must say, that I don't fully understand the help text and just remember that `git checkout <path>` throws away my local uncommitted changes.
Also note that 'widget' could've also easily been a typo for a branch (maybe they meant 'widgets' or something). Meaning that even if you only stick to uses of git checkout for branches, you're not safe (unless you're infallible).
Probably a feature given how many gazillion meanings they've given to checkout intentionally, but I have no clue. Hopefully it got the point across though ;) and I'm pretty sure it's not the only way to lose info in git...
In a near future, hopefully we will have two new commands, git-switch and git-restore. The former is only about switching branches, the latter restoring files. Then you can stay away from the overloaded git-checkout.

See

https://github.com/git/git/blob/pu/Documentation/git-switch....

https://github.com/git/git/blob/pu/Documentation/git-restore...

That's awesome :) though this is just one way to lose files.
Yeah some of those ways are known and there may be a way to recover those lost changes. It's still too early to see if something will materialize.