Git: when do commit?

Hi,

I’m going to start using Git for version control for a project (I’m a single developer). Are there any best practice guidelines in terms of when to Commit changes? For example, if I change or add a feature, then I can see that it would make sense to Commit after the feature is “ready”. However, if there are little bugs that I fix (which there will be as my site goes Beta…) should I commit each one? Or should I group them together in a Commit even if the bugs aren’t related?

This applies to version control generally, not just git, but I would strive to commit each fix individually. That way, each commit message can describe the bug being fixed and the solution that fixed it. Plus, if later on you decide to revert one of the fixes (maybe there were unforseen side-effects), then it’s much easier if it was its own commit.

But notice, also, that I said “strive” to commit each fix individually. Sometimes it’s just much more convenient to do one big commit. I think it’s OK to bend the rule from time to time, but try not to.

1 Like

Hi Jeff,

Than you for your input! And, just to be clear, for you personally, would you (tend to) even commit changes such as a small change in the CSS (for example, “Gosh, I sure wanted that border to be 2px instead of 1px.”)?

I would if it constituted a single logical change. For example, if I decided that I needed to change all borders in css from 2px to 1px then I would treat it as a single logical change for “changing border widths in the layout” - then I would not commit every single border change but all in one go.

Small logical commits allow you to revert easily. I once had a very simple web site with a few pages and I had to change a phone number in a few places along with a name and opening hours - because the owner went on vacation - that was a single commit. Then I did a few layout changes which resulted in a few more commits. Then when the person was back from vacation I simply reverted that initial commit and the phone numbers and other associated stuff were reverted automatically by git. This would have been more complicated if I combined too many or too few changes in the commit.

1 Like

Very clearly articulated! Thank you…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.