3 ms·
> If you mistype it and nuke more than the last commit, that's also a bit bad - and fairly easily done. If you ever run into this, you can use `git reflog` to
by folex 5y ago
> If you mistype it and nuke more than the last commit, that's also a bit bad - and fairly easily done.
If you ever run into this, you can use `git reflog` to see the history of your local actions. It's possible to revert almost any action with it.
Reset a few commits that you've never pushed to remote? No worries! Just go to `git reflog`, find a point before it happened, and `git reset` to it.
$ git reset --hard HEAD^^ # OOPS
$ git reflog
c48300f3 (HEAD -> master) HEAD@{0}: reset: moving to HEAD^^
527e26e0 (origin/master) HEAD@{1}: commit: air-interpreter-wasm = "=0.14.10"
$ git reset --hard HEAD@{1}
And you're back before "OOPS" :) It's really hard to lose changes once they've been committed.
- rich_sasha 5y agoYes, except... again, this is fighting fire with fire. If you don’t know git internals, mistype a non-obvious command and lose a bunch of commits, then “look in the reflog” advice is frankly adding insult to injury.
- gigatexal 5y agoThe age old adage applies here: know your tools.
- Osiris 5y agoAnd he knows it well enough to prefer a different tool. What's right for one isn't right for all.
- clojureyoureyes 5y agoSoftware is for people, not for software itself. I want to get things done fast and with less cognitive load, magit allows me to, git doesn't.
- sa1 5y agoIf it was that easy, https://blog.waleedkhan.name/git-undo/ https://blog.waleedkhan.name/git-undo/ wouldn't be a thing.
- dmurray 5y ago> It's really hard to lose changes once they've been committed. I've still managed to do it (or maybe I used git rm to delete some files that weren't committed?) so let me give one more shout out to 'git fsck' which saved me here.
- matheusmoreira 5y agoThe reflog is awesome! It keeps pointers to commits that have been dropped, rewritten by rebases, stuff like that. Git is garbage collected, even if a commit is dropped from a branch it won't simply disappear immediately afterwards. The object is still in the git repository and it can still be reached, most easily through the reflog. Only when garbage collection is performed will any unreachable commits be deleted.