News for hackers. Stuff that matters.
Re:Git undo: We can do better by kahkeng on Monday June 21, 2021 @02:02PM (#27581808)
I find it pretty useful to use the `--patch` or `-p` option (also a mnemonic for "prompt") to various commands:

`git add -p`: prompt which hunks should be added to staging

`git checkout -p`: prompt which unstaged hunks should be thrown away

`git checkout HEAD^ -p`: prompt which hunks from HEAD should be discarded

`git reset -p`: prompt which currently-staged hunks should be unstaged

`git reset HEAD^ -p`: prompt which hunks from the HEAD commit should be unstaged

Nice thing is that you get interactive yes/no prompts with a preview of the change for each hunk, and you can also quit early if you realize it's not the command you want.

Doesn't fully address the potential for lost changes, but slows it down by adding an interactive roadblock for each change.

Re:Git undo: We can do better by seoaeu on Tuesday June 22, 2021 @12:06AM (#27587881)
Frustratingly `git add -p` adds a new and exciting way to accidentally lose "work": You can type `git commit -a` and all of a sudden all your manual selections of different hunks to include/exclude are irreversibly gone
Re:Git undo: We can do better by secondcoming on Monday June 21, 2021 @05:11PM (#27584557)
hunk?
Re:Git undo: We can do better by cerved on Tuesday June 22, 2021 @03:51AM (#27589069)
noun

1. a large piece of something, especially food, cut or broken off a larger piece.