7 ms·
hey Linus, undo last 1 git command (as though it had never been entered): git undo 1 thanks.
by logicallee 9y ago
hey Linus, undo last 1 git command (as though it had never been entered):
git undo 1
thanks.
- emodendroket 9y agoI'll bet between the reflog and aliases you could do that.
- kccqzy 9y agoHow would you undo "git reflog expire"? How would you undo "git push origin -f"?
- majewsky 9y ago> 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".
- hdhzy 9y ago> 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.
- emodendroket 9y agoWell let me put the question back to you: can changes to git provide undo for literally every command?
- logicallee 9y agoI'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.
- emodendroket 9y agoSo write a script and assign an alias.
- oblio 9y agoYou'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-intermediacy/ https://blog.codinghorror.com/defending-perpetual-intermedia...).
- emodendroket 9y agoA 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.
- deleted 9y ago[deleted]
- gknoy 9y agoYou can make a bash script named `git-undo` , put it in your path (I use ~/bin): #! /bin/bash git reset HEAD~1 && git checkout .
- emodendroket 9y agoYou can assign git aliases that execute shell commands by prefixing with an exclamation mark.
- Ajedi32 9y agoWouldn't work with commands like `git reset --hard` or `git checkout --force` though. Those commands delete uncommitted changes permanently.
- falcolas 9y agoOnly works for commits, but it's a very useful alias I've picked up. [alias] undo = reset HEAD~1 --mixed
- postozoan 9y agoHow about git uncommit? Undo suggests it might work for other actions like pushing