Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Source Control Merges by Trimming Trailing Whitespace Made Easy

DZone's Guide to

Source Control Merges by Trimming Trailing Whitespace Made Easy

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

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:]]*$//"



Source: http://bitkickers.blogspot.com/2011/08/easier-source-control-merges-by.html

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}