tags:

views:

74

answers:

3

When I copy a file over top of another file in a git controlled directory... I'm seeing git think that the whole file has changed instead of one small hunk... why?

Here is an example of what I mean... http://github.com/cmodien/fileupdatetest/commit/90309ed099e257cd98218b4504cd2cd3a3a47a27

OK... I checked the line endings on the file... The original file has crlf line endings. The file that I pasted over the original has lf line endings. Which makes sense I guess... I got the original file from a windows user and I received the new file from a mac user.

How do I fix this?

+3  A: 

As mentioned on twitter, (@adymitruk) you have an issue with line endings. The AutoCRLF setting is probably not set to "false" as it should be - unless you are doing cross-platform development.

The solution is to set it to false, fix the line endings set the autocrlf to false then commit. When this is done, you will be able to copy those files and then only see the actual changes.

adymitruk
Thanks Adam... I actually did not have that flag set... and I was attempting to add that flag as I was assuming that was why git is seeing the whole file as modified... but setting that flag to true and running a series of tests didn't seem to fix the problem. I have since removed that flag from .gitconfig. The problem still exists. I'll code up an example and throw it on github.
Clint Modien
This was annoying for me too when I started to use Git. Once you have autocrlf set to false, you won't have that problem. You will still need to do one clean up commit to set the line endings to what they are natively.
adymitruk
A: 

Hi,

There are two common scenarios in which this can happen:

  1. Whitespace is damaged. Your editor might be converting spaces to TABs or viceversa: just set it to use Linux CodingStyle to solve the problem.
  2. Line endings are damaged. Set core.autocrlf to false and see this discussion about a new core.eol variable.
Ramkumar Ramachandra
A: 

I used this to fix the problem...

http://stackoverflow.com/questions/1510798/trying-to-fix-line-endings-with-git-filter-branch-but-having-no-luck/1511273#1511273

I originally tried to follow this... http://help.github.com/dealing-with-lineendings/ but it was somewhat unclear that on mac/nix you need to set core.autocrlf to input and not true.

The other slight complication was that I had some files ignored in my git ignore that I needed to fix as well... so this command:

git diff --cached --name-only -z | xargs -0 git add

was failing... so I had to run this...

git diff --cached --name-only -z | xargs -0 git add -f

to force it to fix the ignored files as well...

Clint Modien