tags:

views:

53

answers:

2

So I've run into this issue. First of all, the GitHub page seems to indicate that this only affects Windows machines. Is that true? I'm experiencing the problem when doing a fresh clone of a migrated repo on OS X.

Secondly, if I do what is suggested in this fix, I end up modifying thousands of files. The problem is that when I look at the diff of the staged changes it appears to have modified the entire file. My question is: won't this make all diffs of future versions of these files as compared to versions before the commit to fix the line-endings useless?

Forgive me if this is an SVN-specific issue, but in SVN changes like this would mean that the diffs would show the entire file changed whenever you attempted to diff versions that spanned the commit where the line-endings were fixed.

+1  A: 

The standard approach, as you say, is to make a new commit that fixes the line endings and therefore changes every line of every file. However, since yours is a newly-migrated repo it might be more appropriate to rewrite all the commits to have the correct line endings in them. You can do this with git rebase or git filter-branch. Doing it with rebase is essentially a manual process, but filter-branch uses a script that you provide. Your script can do anything it wants, to the entire tree, and the result will be saved as the new version of the commit.

The exact details of the script will depend on your particular situation, because you won't want to try to change the line endings of binary files. However, if you know the file name patterns, you can use the find command to generate a list of all the matching files in the tree, and use this with the xargs command to run fromdos on them to convert the line endings. For example:

#!/bin/sh
find . \( -name '*.cpp' -o -name '*.h' \) -print0 | xargs -0 fromdos

Note that you have to run the script for every commit, because git stores entire files, not diffs.

And be sure to take a backup of your .git directory beforehand, in case it all goes wrong!

Neil Mayhew
A: 

You could just use this option:

   -w, --ignore-all-space
       Ignore whitespace when comparing lines. This ignores differences
       even if one line has whitespace where the other line has none.
Dustin