简体   繁体   中英

How to configure my Notepad to use git diff

I have an question to configure Notepad++: I use Notepad++ in Windows to edit my code. And when I do git diff in Linux, tous les lines show up as modified. In fact, I'm sure I opened the file but I didn't modify it in Notepad! I think it is a configuration problem of notepad, when I open a file in notepad, all the lines break are changed. So the git diff will show me that I "modified" all lines. Could you tell me how to resolve it?

Looks like the code you are editing has been committed to Git with Unix line endings (LF). Notepad++ converts line endings to CRLF, which is typically used on Windows.

You can go about solving this issue in one of two ways.

If you only intend to edit your code with Notepad++ on Windows, you can use Edit > EOL conversion > UNIX/OSX Format to convert all of the line endings in the edited file to the Unix format.

Otherwise, you may configure Git to checkout Unix line endings as CRLF and commit them as LF via core.autocrlf config option. See the excerpt from the documentation below:

If you're programming on Windows and working with people who are not (or vice-versa), you'll probably run into line-ending issues at some point. This is because Windows uses both a carriage-return character and a linefeed character for newlines in its files, whereas Mac and Linux systems use only the linefeed character. This is a subtle but incredibly annoying fact of cross-platform work; many editors on Windows silently replace existing LF-style line endings with CRLF, or insert both line-ending characters when the user hits the enter key.

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 CRLF when you check out code:

$ git config --global core.autocrlf true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM