4 ms·
I don't get this "afraid of losing something" mindset at all. In fifteen years, I've "lost" some minor changes maybe 3 or 4 times, and this was mostly with SVN,
by _pmf_ 7y ago
I don't get this "afraid of losing something" mindset at all. In fifteen years, I've "lost" some minor changes maybe 3 or 4 times, and this was mostly with SVN, which does not have the safeguards that Git has. The only thing that I am moderately afraid of is pushing to the wrong remote branch.
- gvd 7y agogit reflog
- mehrdadn 7y ago> I don't get this "afraid of losing something" mindset at all. In fifteen years, I've "lost" some minor changes maybe 3 or 4 times, and this was mostly with SVN, which does not have the safeguards that Git has. The only thing that I am moderately afraid of is pushing to the wrong remote branch. I can lose something for you in 2 seconds in git. Have fun e.g. recovering from this: $ git init $ mkdir -p widget && echo Introduction > widget/readme.txt $ git add widget $ git commit -m "Initial commit" $ echo Conclusion > widget/readme.txt $ git checkout widget $ cat widget/readme.txt # No "Conclusion"??
- fileeditview 7y agoWow just tried this.. is this considered a bug or a feature and where can you read about this if it is intended behavior?
- mehrdadn 7y agoProbably 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...
- bicolao 7y agoIn 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.txt https://github.com/git/git/blob/pu/Documentation/git-switch.... https://github.com/git/git/blob/pu/Documentation/git-restore.txt https://github.com/git/git/blob/pu/Documentation/git-restore...
- chappi42 7y ago`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.
- mehrdadn 7y agoAlso 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).
- rusk 7y agoWhat you did there is the equivalent to a `revert` in SVN ... I'm not sure what the issue is? Why would you checkout `widget` and not expect local changes to be overwritten? Like, that checkout reverts is one of the first things you learn with git ...
- mehrdadn 7y ago> What you did there is the equivalent to a `revert` in SVN ... I'm not sure what the issue is? Why would you checkout `widget` and not expect local changes to be overwritten? Like, that checkout reverts is one of the first things you learn with git ... Why would you sudo rm -rf / and not expect to destroy your system? Why is --preserve-root the default when that's clearly not what the command means? Like, that -rf wipes everything recursively is one of the first things you learn with rm... Also see https://news.ycombinator.com/item?id=19907882 https://news.ycombinator.com/item?id=19907882 (P.S. also note the question wasn't even about whether this is expected behavior, it was just about whether it's possible to lose information when using git.)
- rusk 7y ago> Why would you sudo rm -rf / Come now, that's being a bit hysterical/hyperbolic. There's plenty of other things you could do in the course of your command-line activities that are at least as destructive. I know your example is meant to be trivial but there are plenty of ways when you're mucking about with pipes to ruin your day. Like I say, "it is known" that git checkout is destructive, and while I can sympathise that perhaps the "-rf" is implicit I honestly can't see how you'd end up doing something like that in day-to-day activities, and if you did ... well if you'd spent any significant amount of time on it it probably should have been checked in anyway. EDIT if you want to see some "good" examples of how you can inadvertently trash everything take a look at https://svnvsgit.com/ https://svnvsgit.com/ (warning, not as impartial as the title might suggest).
- mehrdadn 7y agoI'm not being hyperbolic or giving a trivial example (whatever that's supposed to mean), I was completely seriously pointing out that people used to apply your exact same victim-blaming logic to that same scenario until others finally made them come to their senses and realize that, just because the user happens to type in a command that tells the computer to shoot him in the face, that doesn't necessarily mean the computer should actually go ahead and shoot him in the face. Somehow you managed to take those 6 words out of context and focus on bashing the example while ignoring the actual real problem I was illustrating with it in your reasoning.
- _pmf_ 7y agoApparently I'm warned when I do this using SmartGit; if you are unable to safely use the CLI tool, maybe you should switch to a safer tool and leave the CLI tools to power users?
- mehrdadn 7y ago> if you are unable to safely use the CLI tool, Way to suggest only incompetent people lose data like this. But yes, GUIs do prevent this to a decent extent. Unfortunately git is not a tool for which switching to a GUI before you're comfortable with the CLI is a good idea. SVN is, but not git. I say this from personal experience as a TortoiseGit user. You really gotta learn the command-line first.
- darkpuma 7y ago> "I can lose something for you in 2 seconds _in_ git." You just demonstrated losing something that was not in git... All you've demonstrated is that neglecting to put something into git is a good way of losing it.