Gitjk – command to undo what you just did in git

  • If you name it "git-jk" rather than "gitjk", you can invoke it as

      git jk

  • I occasionally wish git had an undo-whatever-I-just-did command, and I've been using it for years.

    The git fixup page comes in quite handy. https://sethrobertson.github.io/GitFixUm/fixup.html

  • Why is sudo hardcoded into so many commands? I'll run your program with privileges if it needs and earned them, thank you very much.

  • It's kind of nice that this just gives suggestions by default rather than running potentially breaking commands.

    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. https://medium.com/git-tips/a4189dd88c40

  • 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).

  • If anyone wants a fish function:

        function jk
            history | head -n+10 | tail -r | gitjk_cmd
        end
    
    Maybe git full undo via automatic snapshotting (branch/stash)? It's fine unless you hit a perf wall on huge repos.

  • Does it work if you call it 2x or more?

  • rebase isn't very hard to implement; you just have to check the reflog.

  • Uh... if you want to undo a git add shouldn't you be doing git reset?

  • Isn't that what git reflog + reset are for?

  • It does rely on history? Well, it won't work for me then — in my history there's only frequently-used commands.

  • sudo hard-coded, and an intolerably stupid name. Next.