Live data from Hacker News

Git Undo

megakemp.com

1–10 of 175 posts

Re: Git Undo

#2
Most git command-lines are lengthy enough to give me time to consider them, so I don't often feel the need to "take back" a git invocation. What I do often screw up, though, is the (almost hypnotic) tapping of y/n when doing a `git {add, reset, checkout} -p` to prepare and clean up a commit.

Ideally, with all of the -p commands, git wouldn't actually apply any of the changes I specified until it was about to quit (i.e. either when I advance past the end of the set of potentially-affected hunks, or I manually type 'q'), and then would prompt me for whether {set of operations I specified} is what I wanted to do. This would leave the -p operations the the flexibility to expose an 'u'ndo.

Re: Git Undo

#3
Nice idea!

The only non intuitive thing might be, that calling e.g. 'git undo' twice doesn't undo the last two changes, but the first undos the last change and the second one undos the undo.

Re: Git Undo

#4
It should automatically skip reflogs created by undo itself, so git undo; git undo be equivalent to git undo 2, and for undoing undo there should be seperate git redo.

Re: Git Undo

#5
This seems dangerous to get used to. I always thought the reflog was supposed to be last-resort. Isn't it?

Re: Git Undo

#8
I always make sure to keep a `git log` in my terminal scrollback buffer, so I can easily `git reset --hard` back to some revision. And if that fails there's indeed always the reflog to fall back to.

Re: Git Undo

#9
The alias is only useful in the simplest use case. Where you just want to undo the latest one change. Reusing undo to revert the undo is counterintuitive.

If you want to know how many steps back you need to undo, you still need to check reflog. This means you're better of just resetting manually to the change you want.

Re: Git Undo

#10
post #2

Most git command-lines are lengthy enough to give me time to consider them, so I don't often feel the need to "take back" a git invocation. What I do often screw up, though, is the (almost hypnotic) tapping of y/n when doing a `git {add, reset, checkout} -p` to prepare and clean up a commit. Ideally, with all of the -p commands, git wouldn't actually apply any of the changes I specified until it was about to quit (i.…

You'd probably really like Magit mode for Emacs then. What you're describing with interactive add becomes trivial since you can stage parts of the diff by selecting them in a region. I can hardly live without Magit these days. Bonus is that it even works on remote hosts via tramp.
Post reply on HN