by est · 4y ago · 0 comments
- Committed wrong? Undo
- Switched to wrong branch? Undo
- Pushed wrong? Undo
- Merged wrong? Undo
- Wrong reset? Undo
There should be a "idempotent" undo for every action in git. If not, warn the user for possible outcomes.
In this way, we can safely learn git via trial & errors.
The only part that isn't easily undo-able is the index and working dir, but that's kinda the point of having an index in the first place. If you overwrite or delete a file without staging it in git, or unstage and then change it, git isn't going to magically restore it with an undo command. And that's fine.
It's without doubt powerful. But hell it's confusing.
I found undo-tree incredibly intuitive.
For every git command, provide a way to undo the previous command, if possible.
For example, `git checkout -b abc`, a `git undo` would execute `git branch -D abc`.
This is just an example, I know you can find many problems and with this approach and edge cases when it doesn't work, but we can make life easier for beginners in most cases.
> Clicking undo two times and going back only one step
Huh? I never meant that. Click undo two times would go back two steps, naturally.
But of course, there are some actions that can't undo, so give user a warning or something.
idempotent means that doing it twice gives the same result as doing it once. So it seems you meant a different word?
Is there a better word to describe this? I am an ESL speaker.
Thinking about this and I realize it could be beneficial in a lot of software. No one RTFMs anymore, and giving them the ability to trial and error makes sense. I know I appreciate it (pushing buttons to see what happens), but I’m not sure how common this approach is in general.
Undoing a wrong push involves so many corner cases that it would be hard to implement. Where I work we are using gerrit and the default project setup doesn't allow direct pushes. Than it's only abandoning a change.
When I started working with git I came from Perforce and CVS. I had the complete wrong mental model in my head because of this which got me trouble understanding why things where not working as expected especially when pushing to remote.
But to really support this well, I think git would need a git commit object which means "reset to previous state".
I hate revert commits but often you have to do them if you make a mistake because usually force pushes will be disabled on master for that reason.
For dev branches it's easy, `git reset --hard` on local then `git push -f` again. This command combination is not that intuitive for beginners.
I agree this action is sometimes hard to recover e.g. on protected branch, so a warning must be given to the user.