DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Diff before commit  (Read 6,450 times)

Poll: Do you diff / review your code changes before you commit them to source control?

Yes, every single change.
6 (86%)
Yes, but only some of it.
1 (14%)
No, I don't think it's necessary.
0 (0%)
No, I think it's a waste of time.
0 (0%)
Total Members Voted: 7

phitsc

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 1,198
    • Participated in NANY Challenge Seven Times
    • Plugin Coding Medal
Diff before commit
« on: November 04, 2010, 12:45 PM »
I was discussing this question with a colleague recently and we were of quite opposite opinions. I'm a proponent of diffing before commit, I consider it to be kind of my personal mini code review. He basically considers it to be a waste of time, saying that he knows what he changed and that he's just committing very often (which I try to do as well, by the way, but never mind).

I'd like to know how you people feel about this question.

Shades

  • Member
  • Joined in 2006
  • **
  • Posts: 2,954
Re: Diff before commit
« Reply #1 on: November 04, 2010, 01:56 PM »
For me 'Diff before commit' is THE golden rule, with the 'Commit often' rule a very close second.

It is definitely not a waste of time, because you will lose a lot more time when reviewing bigger pieces from other developers and how their changes will affect yours.

You can use 'lazy methods' for coding...never for committing!
The easy path is usually downhill...

f0dder

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Re: Diff before commit
« Reply #2 on: November 04, 2010, 02:54 PM »
Depends on what I've been doing.

If I've been working on something for hours before committing, I definitely do look at diffs in order to write a proper commit message. For shorter-interval commits, the changes are usually small enough that I can remember all of what I've been working on. The more often I commit, the less need I have for looking at diffs. Also helps a lot to work on a single feature at a time (I need to force myself in the habit of doing that - take note if I find other stuff that needs bugfixing/refactoring and modify that after a feature is complete, or do it in a second branch).

A few times, the pre-commit diff has caught silly bugs... but that has always been tied to not committing often enough.
- carpe noctem

Eóin

  • O'Callaghan
  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
Re: Diff before commit
« Reply #3 on: November 04, 2010, 03:42 PM »
When doing a commit through TortoiseGit, it lists the changed files and double clicking on one shows a diff. So I usually check the diffs only if I spot something out of place in the file list.
Interviewer: Is there anything you don't like?
Bjarne Stroustrup: Marketing hype as a substitute for technical argument. Thoughtless adherence to dogma. Pride in ignorance.

housetier

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,321
    • Gathering Badge
Re: Diff before commit
« Reply #4 on: November 04, 2010, 04:34 PM »
I always diff every single file before commiting. I don't make exceptions, I have caught many mistakes this way.

Since I also commit often, the changesets are small so it is easily and quickly done.

I find it difficult to believe for someone to know of all the changes that were made. I know that not double-checking will lead to mistakes: our company hired subcontractors and we regularly had to remove their debug statements and such from the code (only if we saw them).

In our team we do several things:
  • branch early
  • branch often
  • commit early
  • commit often
  • push early
  • push often

Of course before you can push you have to pull, but our git server will remind us :)

I was praised for the quality my work and got a raise recently. I will continue to double check every change, every file. "diff" can save you a lot of trouble!

mwb1100

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,645
Re: Diff before commit
« Reply #5 on: November 04, 2010, 04:44 PM »
For me, diff-before-commit is in the same category as test every change before commit.  When I decide not to do it - usually because the change was so small, that there's *no way* it could cause a problem (like fixing a spelling mistake in a comment) - invariably some dumb-ass thing breaks the build or causes a crasher bug.

And diff-before-commit is really a pretty quick and easy sanity check (it's not like I review every changed line - it's more of a quick verification that I'm checking in what I'm expecting to check in, and not checking in stuff I shouldn't be).

sagji

  • Participant
  • Joined in 2010
  • *
  • Posts: 25
Re: Diff before commit
« Reply #6 on: November 08, 2010, 04:20 PM »
For me the diff before commit is the final approval step.
It is were I make sure of code quality - conformance to coding style and naming convention.
Make sure that any test code is removed.
Make sure I have tested all code paths.
Make sure that all changes correspond to something in the change description - even if it is just "review changes"
Make sure that all required changes have been done.

The only time I don't do the diff is if there is no decision in the change - such as adding in an update from an external source (e.g. updating to a later version of a 3rd party library.)

Original address: https://www.donationcoder.com/forum/index.php?topic=24460.0