Git seems to be confused about whether a file has changed (with autocrlf = true)

I have this rule set in my git config:

autocrlf = true

      

to avoid the problems we had where our designers (who use mac) are unable to open text files that were saved by our development team (who use a mix of mac and linux). One file in particular (which was recently created) is causing the problem: git thinks there is nothing to do, but won't let me check out another branch.

$ git status
# On branch master
# Your branch is up-to-date with 'dreamhost/master'.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   script/resource_library/fix_mp4_moov.sh
#

$ git commit -a -m "line endings changed again"
warning: LF will be replaced by CRLF in script/resource_library/fix_mp4_moov.sh.
The file will have its original line endings in your working directory.
# On branch master
# Your branch is up-to-date with 'dreamhost/master'.
#
nothing to commit, working directory clean

$ git pull
Already up-to-date.

$ git push
Everything up-to-date

$ git checkout feature/my_classes_v2
error: Your local changes to the following files would be overwritten by checkout:
    script/resource_library/fix_mp4_moov.sh
Please, commit your changes or stash them before you can switch branches.
Aborting

      

So cmon git, is this changed or not? Think about it. Usage cat -v

in the file does not show any special line ending characters:

$ head -3 script/resource_library/fix_mp4_moov.sh | cat -v
#!/bin/bash

VIDEO_DIR=$1

      

Can anyone tell me how to set this directly? thanks Max

EDIT - if I write to a file in vim and do set ff=mac

, then I can commit this and push it. But that breaks it for me - I can't get it to run because the shebang line is not being handled properly by bash.

EDIT 2 - git diff results.

$ git diff script/resource_library/fix_mp4_moov.sh
warning: LF will be replaced by CRLF in script/resource_library/fix_mp4_moov.sh.
The file will have its original line endings in your working directory.

      

+3


source to share


1 answer


Just tuning core.autocrlf=true

is not a magic bullet. All you did was keep all the data in the repository (with line mismatches) the same, but now you've promised Git that the data in the repository has normalized line endings \n

.

This is not true of course, because the store still has the same end-of-line mismatch it did before you set it core.autocrlf=true

.



You need to normalize your line ends in the repository for all sanity.

+3


source







All Articles