Make Git “LF will be replaced by CRLF” warnings go away

前端 未结 6 1145
旧时难觅i
旧时难觅i 2020-12-07 14:06

I have setup Git so it doesn\'t commit inconsistent line endings. The problem with that is a whole pile of files appear modified even though they are not. What do I type to

相关标签:
6条回答
  • 2020-12-07 14:25

    You can just delete and re-checkout the offending files from the index like this:

    rm <files>
    git checkout -- <files>
    

    Or, if they are the only modified files (be careful with this command), you can script it like this:

    git diff --name-only --diff-filter=M | xargs rm --
    git checkout -- .
    

    On a GNU system you can use a slightly safer pipe, but you don't appear to have spaces or other delimiting characters in your filenames in any case.

    git diff -z --name-only --diff-filter=M | xargs -0 rm --
    
    0 讨论(0)
  • 2020-12-07 14:29

    Note that note all of the above fixes may work for you, for example you might have received the code through a simple file transfer. You can accept each warning by pressing ENTER, but on on large repos that can take ages. Another way to ignore the conversion on code that has already been checked-out and edited is to create a patch file:

    git diff > changes.patch
    
    0 讨论(0)
  • 2020-12-07 14:34

    This might happen if you change core.autocrlf config variable (if I understand your problem correctly).

    If you are at clean state, i.e. just after commit, and you don't have uncomitted changes, forced re-checkout and removing index should do the trick:

    The below command git reset --hard HEAD will make your current branch to point to the latest commit and all uncommitted code will be lost. Make sure to commit the code or take the backup

    $ rm .git/index
    $ git reset --hard HEAD
    

    That, I think, would sync both working area files, and the index (staging area) to follow crlf settings.

    0 讨论(0)
  • 2020-12-07 14:40

    I had this problem when creating new Xcode project. My solution for this problem:

    In terminal write

    $: git config --global --edit
    

    Then in git config file change safecrlf to false. My settings:

    [core]
        autocrlf = input
        safecrlf = false
    

    I know git have cmd line tools for this but they don't work for me. And then Xcode create git repos without any problem.

    0 讨论(0)
  • 2020-12-07 14:44

    Try this, it worked for me:

    cd src/au/policy/dao
    dos2unix
    

    If there are other files in that folder, then you'll want to break it up into the following (otherwise it will try to do it on every file in any subdirectories, which may take a while):

    cd src/au/policy/dao
    dos2unix EmailQueue.java
    dos2unix EmailQueueFactory.java
    dos2unix PolicyPublisher.java
    

    It ran really quick on my machine and fixed all of the line endings, and it's a little simpler and easier than some of these other fixes.

    0 讨论(0)
  • 2020-12-07 14:47

    Only thing I can think of is to check if core.safecrlf is set to warn.

    git config --get core.safecrlf

    I think possible values are true, false, and warn. I believe that setting to false will resolve the warning, though it may not be a good idea.

    0 讨论(0)
提交回复
热议问题