←back to thread

Oh Shit, Git?

(ohshitgit.com)
464 points Anon84 | 1 comments | | HN request time: 0.202s | source
Show context
frakt0x90 ◴[] No.42730958[source]
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.
replies(3): >>42731034 #>>42731267 #>>42736129 #
wruza ◴[] No.42731034[source]
This should be a built-in

  git unshit
Or

  git add --unshit -f ~HEAD^^
If you’re using git version <= 2.844.
replies(1): >>42732154 #
maleldil ◴[] No.42732154[source]
Jujutsu 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).
replies(2): >>42733795 #>>42742042 #
1. blharr ◴[] No.42742042[source]
Such 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.