How often should you commit?

Programming, for all ages and all languages.
Post Reply
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

How often should you commit?

Post by earlz »

Hi, I've often asked myself exactly when to commit my code... should I commit after I get a new feature working? Of course commit when you fix a broken build(missing file, etc)

exactly how long do all of you wait until commiting? and what do you do when you write 200 lines of code reworking almost everything(and breaking everything while in progress), but discover that something went horribly wrong in the last 10 minutes of your coding?
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: How often should you commit?

Post by Troy Martin »

I don't commit for much more than releases. And when something goes horribly wrong, I attempt to debug my code. If that doesn't work, I put it away in my "strange or broken code" folder and restore the old one.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: How often should you commit?

Post by Kevin »

Commit early, commit often. ;)

With git you can simply throw local development branches on the problem - they can even break compilation without hurting anyone. When you're done with the changes and have reached a new working state, you merge things back into the master branch. Before merging you even can rewrite the version history to be a nice patch series if you like (being able to edit existing commits in my local branches is actually one of the things I like most about git).
Developer of tyndur - community OS of Lowlevel (German)
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: How often should you commit?

Post by Troy Martin »

Welcome to the forums, Kevin!

I prefer SVN over git for simplicity. That and the fact it works good for smaller teams (say two or three people.)
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: How often should you commit?

Post by Kevin »

You might be right that SVN is more intuitive than git and git has a steep learning curve in the beginning. But it's really the same thing as with vim: It's powerful and once you know how to use it you don't want to miss it. I even use it as a better SVN client for some projects which officially use SVN for their main repository (a nice example is qemu which still uses SVN, but basically all developers use git - including the maintainers).
Developer of tyndur - community OS of Lowlevel (German)
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: How often should you commit?

Post by piranha »

I tend to commit less often, with bigger commits toward the beginning of a version, but towards the last few days before the release I commit a lot (bug fixes, minor last min. things)

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: How often should you commit?

Post by AndrewAPrice »

We usually commit at the end of each day before we go home (we skip this step if we know there are bugs that are going to majorly affect the other programmers). We'd also do a massive number of commits in a day if we were working closely to another programmer.

I guess how often you commit depends on if your source code is available to the public or just internally. If it's just internal and you're working with another programmer than you can often commit buggy code (provided you warn the other programmers) - this is what branching is suppose to be for, but it usually becomes too much of a hassle so we work out of trunk.

I think committing at the end of the day will suffice for open source projects.
My OS is Perception.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: How often should you commit?

Post by xyjamepa »

I commit after getting the job done,when the code works perfectly,
I don't commit in the middle of coding unless there's somthing really important.
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: How often should you commit?

Post by Combuster »

I generally commit when I have the next feature implemented.

And sometimes I commit half work when I expect that I will be editing my code on a different computer next time. (which I only do because I'm the only user of my OS' repository, in work I wouldn't dare do that)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: How often should you commit?

Post by Solar »

A commit should address one issue, one issue only, and - if possible - that issue completely.

Commit often enough that a crash-and-burn of your workstation won't lose you much work. (This doesn't really apply for repo's kept locally, but it's still a good rule-of-thumb.)

Commit seldom enough not to break the build or leave an issue half-fixed (unless you're expecting to leave the project for some time and somebody else wants to take over).

A good benchmark for commits is the comment attached to the commit.

Good:
  • Bug #1432 - buffer overflow in module XYZ. Fixed.
  • Changed code from char[] to std::string.
  • Backports from branch 0.3.
  • Sync'ed with upstream release 0.4.23.
Bad:
  • Various fixes.
  • Completely reworked everything.
  • This doesn't fix it, but it's better now.
Every good solution is obvious once you've found it.
User avatar
Steve the Pirate
Member
Member
Posts: 152
Joined: Fri Dec 15, 2006 7:01 am
Location: Brisbane, Australia
Contact:

Re: How often should you commit?

Post by Steve the Pirate »

I really like Git, and try to commit something as soon as a single feature is working. Like Solar said, you really should only address a single feature in a commit, but sometimes that's a bit difficult. Fortunately though Git makes it really easy to only add the files (or even just the parts of files) that you want, and branching is absolutely effortless, so if you're working on a big, complex feature that will break things, it's easy to just make a branch and keep that up to date so you don't loose any code if your drive dies. And that way you don't annoy any other developers or anyone that wants to see the source by breaking your main tree.
My Site | My Blog
Symmetry - My operating system.
User avatar
linuxfood
Member
Member
Posts: 38
Joined: Wed Dec 31, 2008 12:22 am

Re: How often should you commit?

Post by linuxfood »

For personal projects, I typically setup a repo as the first step (git user). The first dozen or so commits follow the "bad commit" format (though I leave myself notes sometimes), since I tend to use source control as a type of "whiteboard" for ideas. Following the first dozen, the commits trend towards, then reach "good commit" format. After reaching "good commit" format, I use branches and alternate checkouts to manage features that break things.
Post Reply