Re:Some best practices for using Git
by Sourya on Monday February 25, 2019 @01:09PM
(#19247830)
Great pointers. However, I have found that even though quite a few people know this, it takes special effort to enforce it. For example, the single-purpose commits. My commits often tend to get a bit large, and include more than one "unit" of work, even though I know the best practices. Any pointers on how to avoid that?
[ Parent
| on HN ]
Re:Some best practices for using Git
by wodenokoto on Monday February 25, 2019 @01:17PM
(#19247920)
It is not ideal, but ... Get a GUI and pick out lines and files and multi-commit your changes.
Re:Some best practices for using Git
by WorldMaker on Monday February 25, 2019 @02:35PM
(#19248641)
`git add --interactive` can be a great tool to learn in this case: https://git-scm.com/book/en/v2/Git-Tools-Interactive-Staging
In particular, the ability to only stage specific "hunks" at a time (interactive "patch" in the nomenclature of git) can make it possible to "untangle" multiple changes in your working directory into separate commits.
Didn't know about that. Thank you.
Re:Some best practices for using Git
by sanketsaurav on Monday February 25, 2019 @01:19PM
(#19247943)
YMMV, but when I'm working on a feature branch that can take some time, I try to break it into pieces to merge into master often. One way to think about this is breaking away from the compulsion to commit the entire thing together in a branch. So I have `feat-x-part-1`, `feat-x-part-2` and so on.
It's important to resist the urge to do push things only on perfection. It works for me.
I try to emphasize that commits should not be thought of as "save points," which seems to be a seductive way to think of them, but as "undo points."