5 ms·
The most painful mistakes beginers endure with git are irrevocable code removal from the current working directory because of bad usage of `git clean`, `git res
by OhNoMyqueen 5y ago
The most painful mistakes beginers endure with git are irrevocable code removal from the current working directory because of bad usage of `git clean`, `git reset` (or `git merge` if you're brutish enough). This problem cannot be solved by using git, because git doesn't have any reference to such code.
- juped 5y agoAlso from deleting their whole checkout.
- nsomaru 5y agoAm I doing things wrong if I have never used these commands?
- jdauriemma 5y agoTry not to think of it in terms of right and wrong. `git clean` is useful, though not "can't-live-without-it" useful. I couldn't imagine my workflow without `git reset`, though, and I recommend checking it out!
- jonahx 5y agoProbably not using git ideally. Do you clean your history after working on a feature?
- rjmunro 5y agoNo, IMHO you are doing things right. I virtually never use those commands, I've been using git for well over 10 years, and have totally got used to all it's quirks.
- anamexis 5y agoI agree, these are the only times I've irreversibly gotten myself into trouble. I think it would be possible to solve these with git, by doing something like automatically running a `git stash --include-untracked` before an operation that can clobber untracked files.
- abdusco 5y agoIf you're using JetBrains products, you can view the history of the changes for the whole project and revert mistakes by right-clicking the project > Show Local Changes. https://twitter.com/abdusdev/status/1403050600925962247 https://twitter.com/abdusdev/status/1403050600925962247
- GordonS 5y agoI use Rider, and this has saved me multiple times! JetBrains IDEs also have the best UI I've come across for conflict merges.
- rags2riches 5y agoDon't forget `git checkout`! When I help people get started with git, I tell them several times to commit as often as they can. If they committed it, I can probably save them when they think they lost something.
- kahkeng 5y agoI find it pretty useful to use the `--patch` or `-p` option (also a mnemonic for "prompt") to various commands: `git add -p`: prompt which hunks should be added to staging `git checkout -p`: prompt which unstaged hunks should be thrown away `git checkout HEAD^ -p`: prompt which hunks from HEAD should be discarded `git reset -p`: prompt which currently-staged hunks should be unstaged `git reset HEAD^ -p`: prompt which hunks from the HEAD commit should be unstaged Nice thing is that you get interactive yes/no prompts with a preview of the change for each hunk, and you can also quit early if you realize it's not the command you want. Doesn't fully address the potential for lost changes, but slows it down by adding an interactive roadblock for each change.
- secondcoming 5y agohunk?
- cerved 5y agonoun 1. a large piece of something, especially food, cut or broken off a larger piece.
- seoaeu 5y agoFrustratingly `git add -p` adds a new and exciting way to accidentally lose "work": You can type `git commit -a` and all of a sudden all your manual selections of different hunks to include/exclude are irreversibly gone
- Leherenn 5y agoA bit less painful, in the sense that you probably won't lose work, but still quite a headscratcher is line endings issues. Not amount of `git checkout .` or `git reset --hard` will help, and you just have massive diffs with no obvious change. I recloned the repo quite a few times in my younger days over this, and I still have to think deeply to be sure to use the correct configuration.
- alxndrr 5y agoTower for Mac supports undoing (and redoing) all working tree actions like staging/unstaging/discarding individual chunks or complete files, undoing applying a stash, everything. Just hit CMD-Z. The feature is coming to Windows soon as well! I am the CTO of Tower, a Git client for Mac and Windows.