Git reset vs. Git revert
pingtech.xyz
pingtech.xyz
On another note, I love how HN can go from complex research papers I struggle to keep up with, to explaining git commands the next day — something I learned within my first month of Git and never had a problem with again. How bipolar.
"git reset --patch" is useful for unraveling changes that were wrongly combined into a single commit.
Rebase, branching, diff, cherry pick, merging is just manipulating a DAG.
When you're on your own branch it's often easier to think of it as a linked list.
Trusting the reflog is key to becoming good at git.
I use interactive rebasing as the backdrop for teasing apart commits that are not the HEAD commit; it provides the navigation through the commits.
The cherry-pick operations that underpin rebase are not what actually does the teasing-apart, though; I do that with with git reset --interactive HEAD^ when I've landed using "edit" on the commit I want to separate.
However, I just find it easier to start from scratch if I changed 4 files at once, wanted the changes spread out over 3 commits, and I did those in the wrong order or something.
Everything has been crystal clear since. I highly recommend it if you use git.
[0] https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified
In the last example (which is actually the most common case in practice), they give wrong instructions. They should only revert the bad commit, not all the following commits. Reverting everything is impractical and useless, and if you want to do that you may as well use revert (which is still a bad idea).
> Really hard to take anything you say seriously when you use the entire aplhabet for your hexadecimal SHA1 examples.
Touche.