Easier source control merges by trimming trailing whitespace

If you do frequent branch merges in any source control system, you have likely encountered merge conflicts. When two branches have legitimate differences, most often you have to resolve those differences by hand. But all too often, when resolving diffs, you end up looking at a lot of "phantom diffs", too. The most common phantom diff is the trailing whitespace difference.

Just like standardization of space/tab between developers, deciding as a team to not commit changes with trailing whitespace can make your merging easier. You could to this with a git hook, or you could just configure your editor to do it.

In Eclipse, this requires a plug-in called AnyEdit. Once the plug-in is installed, enabled this option is under Preferences -> General -> Editors -> AnyEdit Tools.

But what about all the code you already have? Ideally you would get all the developers on a unified branch, perhaps after a sprint ends, and update the whole codebase at once to remove trailing spaces. In Linux, you run the following from the root of your code directory. Note the extension list in the first part.

echo "*.py,*.js,*.css,*.html" |xargs -d, -I ext find . -type f -name ext -print0 |xargs -0 sed -i .bak -e "s/[[:space:]]*$//"