News for hackers. Stuff that matters.
Re:Idiot Proof Git by est on Thursday November 10, 2022 @12:05AM (#33542465)
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.

Re:Idiot Proof Git by stephen_g on Thursday November 10, 2022 @12:25AM (#33542592)
That'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.
Re:Idiot Proof Git by arcanemachiner on Thursday November 10, 2022 @12:28AM (#33542613)
git undo -f
Re:Idiot Proof Git by notpushkin on Thursday November 10, 2022 @02:20AM (#33543271)
Since 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.
Re:Idiot Proof Git by ykonstant on Thursday November 10, 2022 @11:36AM (#33549058)
Should also support the gnu long-option, git undo --fuck-up
Re:Idiot Proof Git by est on Thursday November 10, 2022 @01:54AM (#33543124)
> 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.

Re:Idiot Proof Git by hoseja on Thursday November 10, 2022 @04:53AM (#33544344)
You can also `revert` which, while staying in history, needs no warning.
Re:Idiot Proof Git by stephen_g on Friday November 11, 2022 @12:35AM (#33557642)
Assuming 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).
Re:Idiot Proof Git by jononor on Thursday November 10, 2022 @03:50AM (#33543872)
If 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".

Re:Idiot Proof Git by stephen_g on Friday November 11, 2022 @12:32AM (#33557623)
The issue is if somebody else has pulled the remote branch and then you remove the commit, suddenly their branch and yours doesn't match. And then they can't push without massaging it.

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.

Re:Idiot Proof Git by rapind on Thursday November 10, 2022 @12:12AM (#33542507)
> 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.

Re:Idiot Proof Git by zenogantner on Thursday November 10, 2022 @04:00AM (#33543940)
Being able to undo an action is is actually a general usability principle that has been around at least since the 1980s :-).
Re:Idiot Proof Git by forgotpwd16 on Thursday November 10, 2022 @07:13AM (#33545308)
The Humane Interface, a book on UIs by J. Raskin, talks about the importance of undo/redo.
Re:Idiot Proof Git by rapind on Friday November 11, 2022 @04:46PM (#33567300)
Fair 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.
Re:Idiot Proof Git by Aleksdev on Thursday November 10, 2022 @12:42AM (#33542720)
Map that bad boy to ctrl + z in terminal and now your talking business!
Re:Idiot Proof Git by xorcist on Thursday November 10, 2022 @05:39PM (#33554611)
Call git every time you background a process? How would that make sense?
Re:Idiot Proof Git by diffeomorphism on Thursday November 10, 2022 @02:17AM (#33543259)
What do you mean by idempotent? Clicking undo two times and going back only one step sounds confusing.
Re:Idiot Proof Git by est on Thursday November 10, 2022 @02:31AM (#33543356)
> 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.

Re:Idiot Proof Git by diffeomorphism on Thursday November 10, 2022 @02:56AM (#33543525)
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?

Re:Idiot Proof Git by est on Thursday November 10, 2022 @05:33AM (#33544623)
Yes 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.

Re:Idiot Proof Git by Xelbair on Thursday November 10, 2022 @05:39AM (#33544656)
I suppose they meant that (most) git commands should be idempotent, and therefore easily reversible.
Re:Idiot Proof Git by diffeomorphism on Thursday November 10, 2022 @10:53AM (#33548249)
Being idempotent does not help much with invertibility, e.g. zeroing out a file is idempotent.

In any case, the above post makes sense if you just delete the word.

Re:Idiot Proof Git by forgotpwd16 on Thursday November 10, 2022 @07:31AM (#33545488)
Less confusing than undo/redo on Emacs. Wanna redo? Just undo your undo after breaking your undo sequence. You broke your undo sequence and want to resume undoing but not redo? Just `M-x undo-only`. What if then only the reverse and just want to redo? Just `Mx undo-redo`. Also keep in mind that if you have some region selected undo only applies to the region rather the file. Unless you use C-/ which always operates on the buffer.

It's without doubt powerful. But hell it's confusing.

Re:Idiot Proof Git by diffeomorphism on Thursday November 10, 2022 @09:32AM (#33546980)
> emacs

I found undo-tree incredibly intuitive.

Re:Idiot Proof Git by alanhaha on Thursday November 10, 2022 @05:56AM (#33544790)
While it may not be accurate, but for "idempotent", did you mean "invertible"?
Re:Idiot Proof Git by seba_dos1 on Thursday November 10, 2022 @06:09AM (#33544870)
git 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.

Re:Idiot Proof Git by chopin on Thursday November 10, 2022 @07:29AM (#33545470)
Besides 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.

Re:Idiot Proof Git by cakoose on Thursday November 10, 2022 @04:29PM (#33553682)