Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

hey Linus, undo last 1 git command (as though it had never been entered):

  git undo 1
thanks.


Only works for commits, but it's a very useful alias I've picked up.

    [alias]
        undo = reset HEAD~1 --mixed


How about git uncommit? Undo suggests it might work for other actions like pushing


I'll bet between the reflog and aliases you could do that.


How would you undo "git reflog expire"? How would you undo "git push origin -f"?


> How would you undo "git push origin -f"?

Remote reflog contains this info (if enabled).

Of course not all commands would be reversible, especially not plumbing.


> git reflog expire

Is there a valid reason to do this in the first place?

> git push origin -f

No standard way to undo that. Only do it if you must, and you absolutely do what's going to happen. Always do a "got remote update" immediately before the force-push and double-check that the remote branch points to what you expect.

As a general rule, "--force" is short for "you better be prepared to deal with the consequences".


Well let me put the question back to you: can changes to git provide undo for literally every command?


Wouldn't work with commands like `git reset --hard` or `git checkout --force` though. Those commands delete uncommitted changes permanently.


I'm requesting the exact syntax I just wrote.

EDIT: the replies to this don't get how feature requests work. yes, I could write this basic feature myself. thanks.


You can make a bash script named `git-undo` , put it in your path (I use ~/bin):

    #! /bin/bash
    git reset HEAD~1 && git checkout .


You can assign git aliases that execute shell commands by prefixing with an exclamation mark.


So write a script and assign an alias.


You're missing his point. Defaults matter. A huge majority of users (80%?) never change the defaults, often for good reasons.

A minor usability investment on the part of 1-2 git developers would prevent thousands of hours wasted by newbies and perpetual intermediates (https://blog.codinghorror.com/defending-perpetual-intermedia...).


A feature like undo is never going to be implemented as a core thing because there are too many instances where it's not clear what it should do.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: