5 ms·
IMHO the single most important idiot proof of git should be a universal "undo" command. - Committed wrong? Undo - Switched to wrong branch? Undo - Pushed wro
by est 4y ago
IMHO the single most important idiot proof of git should be a universal "undo" command.
- 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.
- rapind 4y ago> In this way, we can safely learn git via trial & errors. 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.
- zenogantner 4y agoBeing able to undo an action is is actually a general usability principle that has been around at least since the 1980s :-).
- forgotpwd16 4y agoThe Humane Interface, a book on UIs by J. Raskin, talks about the importance of undo/redo.
- rapind 4y agoFair enough, I should have been clearer. I’m thinking about extending it to CRUD apps for example. I haven’t personally seen any do that, and it might get really involved due to dependencies, integrations, etc.
- stephen_g 4y agoThat's not a bad idea. Pushed wrong is pretty hard to recover from (since you often aren't allowed to rewrite history on the remote), so I don't think there could be an easy 'undo' action for that, but the other ones could potentially be done.
- arcanemachiner 4y agogit undo -f
- notpushkin 4y agoSince we're talking about beginners (dare I say, newbies), I think adding this flag would just make them use it all the time. Perhaps just for this command we should only allow --force-remote, so that they have to (1) type it out explicitly and (2) think about what exactly they're doing.
- ykonstant 4y agoShould also support the gnu long-option, git undo --fuck-up
- est 4y ago> since you often aren't allowed to rewrite history on the remote 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.
- hoseja 4y agoYou can also `revert` which, while staying in history, needs no warning.
- stephen_g 4y agoAssuming your remote allows you to force push. Also you need to specify where to reset to because 'git reset --hard' will just reset you to HEAD, so you actually need to do 'git reset --hard HEAD~' (usually I don't use --hard for this either because often there's some work I want to keep from the commit).
- jononor 4y agoIf the result of the undo is that the remote branch (say main) is back at the point where it was just before, then that is actually a kind of change one could allow? As it does not rewrite history, just reset to previous point in time. But to really support this well, I think git would need a git commit object which means "reset to previous state".
- Aleksdev 4y agoMap that bad boy to ctrl + z in terminal and now your talking business!
- xorcist 4y agoCall git every time you background a process? How would that make sense?
- diffeomorphism 4y agoWhat do you mean by idempotent? Clicking undo two times and going back only one step sounds confusing.
- est 4y ago> What do you mean by idempotent? 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.
- diffeomorphism 4y agohttps://www.merriam-webster.com/dictionary/idempotent https://www.merriam-webster.com/dictionary/idempotent idempotent means that doing it twice gives the same result as doing it once. So it seems you meant a different word?
- est 4y agoYes I mean undo would always restore the git to a previous state no matter what kind of commands you typed (best effort). It's perfectly symmetrical forward and backward operation which will guarantee restore to the same repo result whether you misstep git once or multiple times. Is there a better word to describe this? I am an ESL speaker.
- Xelbair 4y agoI suppose they meant that (most) git commands should be idempotent, and therefore easily reversible.
- diffeomorphism 4y ago
- alanhaha 4y agoWhile it may not be accurate, but for "idempotent", did you mean "invertible"?
- seba_dos1 4y agogit is already an undo mechanism itself. Commits are immutable. `git reflog` provides an undo log for pretty much every operation on the repository. `git push` shows the previous state of the branch which you can use to easily undo what you just did on the remote. 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.
- chopin 4y agoBesides a wrong push, the reflog gives you all that albeit not very intuitive. I admit that I often put tags at the current stage before trying anything advanced in order to find the last known good state easier. 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.
- cakoose 4y ago"git undo" tool: https://github.com/arxanas/git-branchless/wiki/Command:-git-undo https://github.com/arxanas/git-branchless/wiki/Command:-git-...