You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Git配置对比:autocrlf=true+core.eol=native与autocrlf=input的差异

Git换行符配置:core.autocrlf=true + core.eol=native vs core.autocrlf=input

Let's dive into exactly how these two setups behave, and when you'd want to use each—line endings are one of those tiny Git details that can cause big headaches if misconfigured.

1. core.autocrlf = true + core.eol = native

First, let's unpack what each part does here:

  • core.autocrlf=true tells Git to handle line ending conversion on pull and push
  • core.eol=native sets the default line ending for files you create locally to match your operating system's native style (CRLF on Windows, LF on Linux/macOS)

How it works:

  • When pulling code from the repo: Git converts all LF line endings in the remote repo to your system's native line endings (CRLF for Windows users, LF for everyone else). So your local working directory will have line endings that feel natural for your OS.
  • When committing code to the repo: Git converts any CRLF line endings in your working directory back to LF before storing them in the repo. This keeps the repo consistent with LF, which is the standard for cross-platform projects.

Ideal use case:

This is perfect for Windows developers working on cross-platform teams. If you're used to seeing CRLF in your Windows editors (like Notepad++ or older Visual Studio versions) but need to collaborate with folks on Linux/macOS, this setup lets you work natively locally while keeping the repo clean and LF-only.

2. core.autocrlf = input

This is a simpler, more "hands-off" config for systems that natively use LF.

How it works:

  • When pulling code from the repo: Git doesn't touch line endings at all. Whatever line endings are in the repo (almost always LF, if it's a well-managed project) stay as-is in your working directory.
  • When committing code to the repo: Git only converts CRLF line endings to LF—if your local files already use LF, it leaves them alone. This ensures the repo stays LF-only without messing with your local setup.

Ideal use case:

This is the go-to for Linux/macOS developers, since those systems use LF natively. It's also great for Windows developers who've configured their editors to use LF by default (like modern VS Code with the "Files: EOL" setting set to \n). You avoid unnecessary conversion steps and keep your local files aligned with the repo's line endings.

Quick Cheat Sheet

  • Use core.autocrlf=true + core.eol=native if you're on Windows and want to keep CRLF locally but contribute to an LF-only repo.
  • Use core.autocrlf=input if you're on Linux/macOS, or if you prefer LF line endings on Windows and don't need CRLF for legacy tools.

内容的提问来源于stack exchange,提问作者Adrian Kalinowski

火山引擎 最新活动