Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jonlabelle/70a87e6871a1138ac3031f5e8e39f294 to your computer and use it in GitHub Desktop.
Save jonlabelle/70a87e6871a1138ac3031f5e8e39f294 to your computer and use it in GitHub Desktop.

Revisions

  1. jonlabelle created this gist Dec 8, 2021.
    49 changes: 49 additions & 0 deletions resolving_git_line_ending_issues_in_docker_containers.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    # Resolving Git line ending issues in Docker containers

    > How to resolve Git line ending issues in Docker containers resulting in many modified files.
    - **Author/Source:** [Visual Studio Code](https://code.visualstudio.com/docs/remote/troubleshooting#_resolving-git-line-ending-issues-in-containers-resulting-in-many-modified-files)
    - **Date**: December 8, 2021

    ---

    Since Windows and Linux use different default line endings, Git may report a
    large number of modified files that have no differences aside from their line
    endings. To prevent this from happening, you can disable line ending conversion
    using a `.gitattributes` file or globally on the Windows side.

    Typically adding or modifying a `.gitattributes` file in your repository is the
    most reliable way to solve this problem. Committing this file to source control
    will help others and allows you to vary behaviors by repository as appropriate.
    For example, adding the following to `.gitattributes` file to the root of your
    repository will force everything to be LF, except for Windows batch files that
    require CRLF:

    ```bash
    * text=auto eol=lf

    *.{cmd,[cC][mM][dD]} text eol=crlf
    *.{bat,[bB][aA][tT]} text eol=crlf
    ```

    Note that this works in Git **v2.10+**, so if you are running into problems, be
    sure you've got a recent Git client installed. You can add other file types in
    your repository that require CRLF to this same file.

    If you would prefer to still always upload Unix-style line endings (LF), you can
    use the `input` option.

    ```bash
    git config --global core.autocrlf input
    ```

    If you'd prefer to disable line-ending conversion entirely, run the following
    instead:

    ```bash
    git config --global core.autocrlf false
    ```

    Finally, you may need to clone the repository again for these settings to take
    effect.