Git and IntelliJ lines separator issue

后端 未结 3 1085
感动是毒
感动是毒 2021-01-11 10:59

I am working in IntelliJ 15.0.3 and using Git through Git Bash (to commit and push changes). When I fetch file from remote git repository it contai

相关标签:
3条回答
  • 2021-01-11 11:29

    While installing git, we will have option to set the checkout as-is and commit as-is.

    If that is not set, we can do with the git config.

    Following command helps you in doing so.

    git config --global core.autocrlf true
    

    As per documentation:

        Git can handle this by auto-converting CRLF line endings into LF when you
     add a file to the index, and vice versa when it checks out code onto your 
    filesystem. You can turn on this functionality with the core.autocrlf setting. 
    If you’re on a Windows machine, set it to true – this converts LF endings into 
    
    0 讨论(0)
  • 2021-01-11 11:36

    Try to add below conifguration to your .gitconfig (for unix based OS only)

    [core]
        autocrlf = input
        eol = lf
    

    You can also make such changes within terminal:

     git config --global core.eol lf
     git config --global core.autocrlf input
    
    0 讨论(0)
  • 2021-01-11 11:37

    IDEA delegates changes resolution to git.

    So you would have to either force desired line breaks in IDEA or to force desired line breaks in git.

    In my case autocrlf true was already present on my PC but the working copy was initially copied from collegue's share where it had been checked out with another setting.

    A clean checkout would resolve the problem but I had some files already changed and wanted to preserve them. This can be worked around by resetting git index for the whole project or just desired subdirectory.

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