3 ms·
I'm not proud of it, but my #1 "Oh shit" git operation is to just delete my local repo, reclone, and reapply the changes. Works really well for me 95% of the ti
by frakt0x90 2y ago
I'm not proud of it, but my #1 "Oh shit" git operation is to just delete my local repo, reclone, and reapply the changes. Works really well for me 95% of the time. The rest I ask dev ops guy to help.
- wruza 2y agoThis should be a built-in git unshit Or git add --unshit -f ~HEAD^^ If you’re using git version <= 2.844.
- maleldil 2y agoJujutsu has `jj undo`, but which undoes whatever was your last jj command, regardless of what it was. It makes much more confident to do an operation I'm uncertain of. And if I regret something many actions down the line, you have `jj op log` (a better reflog).
- zahlman 2y agoIf you `jj undo` a second time, does it redo (undoing the undo), or does it back up another step?
- steveklabnik 2y agoIt redos, there's discussion about if and how this should change: https://github.com/jj-vcs/jj/issues/3700 https://github.com/jj-vcs/jj/issues/3700
- stouset 2y agoFor background, this is because the `undo` itself is an operation pushed onto the top of the stack. It is a little counterintuitive.
- blharr 2y agoSuch a simple operation, but it'd probably fix 95% of problems I've had with git. "Uh oh, I tried to checkout a branch from remote by doing `git checkout origin/some-branch` instead of `git checkout some-branch` and made a couple source changes. Now I'm in detached head state. What is detached head ? I have to stash my revisions? Can I make a new branch with the same name or do I need to delete the origin/some-branch that I'm on?" When you could be able to just revert the "operation" and check out the correct branch, that's amazing.
- spokaneplumb 2y agoI've been using Git for almost 15 years, and have twice built programs/products that use Git internally to achieve certain results (that is, the program/product itself uses Git for things, not just using Git to manage the source code for the program/product) and... sometimes before doing something a little gnarly in Git I'll still just do "cp -R .git ../git-backup" or something like that, so I can replace my entire .git dir with an older copy if I screw it up too bad. It's a ton faster than figuring out the right way to un-fuck any particular operation or set of operations.
- fragmede 2y agoReflog is your friend. git break-my-shit git reflog ... output saying where you were before things broke ... grab the good commit sha git reset --hard good_commit_sha_from_reflog
- compiler-guy 2y agoAnd yet up above we have others recommending to never, ever, use `git reset --hard ...`.
- psyclobe 2y agoThe same people probably want to ban knives!
- spokaneplumb 2y agoThe copy-the-.git-dir trick works for worse issues than can be solved with a single reset --hard. Damn near anything, really, as long as you haven't touched any remotes. It also works if you don't remember/understand how you broke it, where it's broken, or which state you need to try to reset to.
- guenthert 2y agoYou're not alone. https://xkcd.com/1597/ https://xkcd.com/1597/