3

I have this rule set in my git config:

autocrlf = true

this is to avoid problems we've had where our designers (who use mac) can't open text files that have been saved by our dev team (who use a mix of mac and linux). One file in particular (which was created recently) is causing a problem: git thinks there's nothing to commit, but won't let me check another branch out.

$ 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 it changed or not? make your mind up. Using cat -v on the file doesn't reveal 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 straight? thanks, Max

EDIT - if i go into the file in vim and do set ff=mac, then i can commit this in and push it up. But, that breaks it for me - i can't run it because the shebang line isn't parsed 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.
Max Williams
  • 32,435
  • 31
  • 130
  • 197
  • does `git status` show anything? Also, related: [LF will be replaced by CRLF in git - What is that and is it important?](http://stackoverflow.com/q/5834014/1983854) – fedorqui Jan 12 '15 at 15:25
  • That's a warning generated by git by the `autocrlf=true` option. – Max Williams Jan 12 '15 at 15:26
  • Interesting. And what does `git diff script/resource_library/fix_mp4_moov.sh` show? – fedorqui Jan 12 '15 at 15:26
  • I would copy the file locally and then `git checkout script/resource_library/fix_mp4_moov.sh ` to get the original and diff them. In my experience git, despite trying to handle this stuff, kind of sucks at this newline business. The issue here is likely that you have a line-ending change locally that will be normalized away on commit so you can't commit a change but can't get git to checkout away from it because it is "different" then the index says it should be. – Etan Reisner Jan 12 '15 at 15:42
  • @fedorqui see edit 2. – Max Williams Jan 12 '15 at 15:56
  • @EtanReisner - just did that, `diff` (plain old `diff`, not `git diff`) says that every line is different. – Max Williams Jan 12 '15 at 16:07
  • Yeah, that's what diff will say for line ending changes. What does `file` report for both the files? What does vim say the `ff` is for both files? – Etan Reisner Jan 12 '15 at 16:08
  • local (copied elsewhere): `set ff` => `unix`. file says `/home/max/fix_mp4_moov.sh: Bourne-Again shell script, ASCII text executable`. checked-out version: `set ff` => `dos`. file says `/home/max/fix_mp4_moov.sh: Bourne-Again shell script, ASCII text executable, with CRLF line terminators` – Max Williams Jan 12 '15 at 16:48

1 Answers1

3

Simply setting core.autocrlf=true is not some magic bullet. All you have done is to keep all the data in the repository (with a mismatch of line endings) the same, but now you've made a promise to Git that the data in the repository has normalized line endings of \n.

Of course, this isn't true, because the repository still has the same mismatch of line endings it did before you set core.autocrlf=true.

You will need to normalize your line endings in the repository for everybody's sanity.

Community
  • 1
  • 1
Edward Thomson
  • 74,857
  • 14
  • 158
  • 187