←back to thread

Oh Shit, Git?

(ohshitgit.com)
464 points Anon84 | 2 comments | | HN request time: 0.001s | 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 #
spokaneplumb ◴[] No.42731267[source]
I'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.
replies(1): >>42731790 #
fragmede ◴[] No.42731790[source]
Reflog 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
replies(2): >>42732258 #>>42743323 #
1. compiler-guy ◴[] No.42732258{3}[source]
And yet up above we have others recommending to never, ever, use `git reset --hard ...`.
replies(1): >>42732305 #
2. psyclobe ◴[] No.42732305[source]
The same people probably want to ban knives!