Sunday, June 24, 2012

Finding differences between files

Whenever you're working on a big project with multiple developers, its always important to keep yourself updated with the latest code changes, scrum meetings are great for that but don't provide the insight into someone's implementation, so whether its time for you to pull/update changes or push/commit changes, its always important to go over all changes that were made, by your coworkers or yourself, its a great way to remind you of everything you did and if you've forgot something or just see someone duplicating code you remember seeing someplace else.

Working with Tortoise versioning (SVN or GIT), I've come across two diff/merging programs, TortoiseMerge and KDIFF3, I'm sure there are plenty of tools, to each his own.

First, lets take a look at TortoiseMerge.

tortoisemerge with whitespaces and inline diff word-wise

The original view is full of dots, lines and arrows, you can't really see the forest for the trees, so lets start by removing the Whitespaces and Inline diff word-wise.

Good, now we can see that only the r changed. 

On with KDIFF3

Not much difference except its not showing the line as deleted on the original side but only that it changed and what changed.

I personally prefer KDIFF3, it looks cleaner to me and when doing merges I can see the original, their version and my version and it makes my life easier figuring out exactly what and how to merge. another plus in my eyes is its ability to compare whole directories.

Keyboard shortcuts for TortoiseMerge when merging are Ctrl-F8 for the next conflict and Ctrl-F9 and Ctrl-F10 for selecting either theirs or mine changes.

And for KDIFF3, Ctrl-PageDown for the next conflict and Ctrl-1,2,3 for selecting base, their or my changes.

To summaries, knowing what's been changed and reviewing your own changes is one of the most important things you need to do as a programmer. Use any diff tool you're comfortable with, be consistent with it and you'll see the quality of code you and the team produce go up because everyone is keeping tabs on everyone.

No comments:

Post a Comment