I occasionally wish git had an undo-whatever-I-just-did command, and I've been using it for years.<p>The git fixup page comes in quite handy. <a href="https://sethrobertson.github.io/GitFixUm/fixup.html" rel="nofollow">https://sethrobertson.github.io/GitFixUm/fixup.html</a>
It's kind of nice that this just gives suggestions by default rather than running potentially breaking commands.<p>But as someone else here mentioned, you really want to understand the reflog in git. Everyone screws up at some point or another, and it's much easier to work through things when you can rely on the reflog to act as a safety net and an anchor of sanity.
The git reflog gets you out of all kinds of messes. <a href="https://medium.com/git-tips/a4189dd88c40" rel="nofollow">https://medium.com/git-tips/a4189dd88c40</a>
I'm pretty sure your fetch logic is not right. First it assumes no arguments are passed. You assume origin/master (which is convention but not guaranteed) and also you assume a refspec isn't passed (in which case you need to rollback FETCH_HEAD).
See also<p><a href="http://blog.kazuhooku.com/2014/04/announcing-unco-undo-changes-to-files.html" rel="nofollow">http://blog.kazuhooku.com/2014/04/announcing-unco-undo-chang...</a>
If anyone wants a fish function:<p><pre><code> function jk
history | head -n+10 | tail -r | gitjk_cmd
end
</code></pre>
Maybe git full undo via automatic snapshotting (branch/stash)? It's fine unless you hit a perf wall on huge repos.