Home > other >  git : nothing changed but mark every line "changed"
git : nothing changed but mark every line "changed"

Time:12-29

IDE : Eclipse & VS code Git tool : source tree, VS code Action : Nothing changed in my code. But when pressing ctrl s, it's able to save and suorceTree will show every line has been edited. The only change I found (show by sourceTree) :

form: import org.apache.poi.ss.usermodel.Cell;␍import org.apache.poi.ss.usermodel.CellType;

to this: import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType;

I'm quite sure that I'm not using any "format code on save" settings, is it a git bug in this version?

trying : ctrl s in vs code, eclipse, wordPad excepting : to edit a line (not changing the whold file when saving) and push to git branch.

CodePudding user response:

By default Git uses LF (Linux) Line Endings, Windows on the other hand pushes CRLF Line Endings.

Git tries makes the assumption that if you are using Windows, you want CRLF, this is good for normal users because programs generally come pre-configured to use CRLF.

If you are using Windows and you are getting false changes reports, it is likely that Git is ignoring the line endings, so when you clone or pull code, it will be in LF. Then when you save your progress in your CRLF-configured editors, each line ending is being changed back to CRLF, modifying the whole file.

This behavior can be altered during the Windows installation of Git, pay close attention to it next time you install Git.

Solution 1: Configure Git

You can configure Git to *replace LF to CRLF when checking out (cloning, pulling...) so you can work in CRLF, and then replace CRLF back to LF when you commit so that you don't commit whole practically unchanged files. The option you want is core.autocrlf, you can do it in your terminal:

git config --global core.autocrlf true

The --global parameter makes this change for your entire user (which you probably want to)

Solution 2: Start using LF

You could configure your Text Editors and IDEs to use LF by default, that way when you clone or pull in LF, you will keep working and saving your work using LF, retaining Git's default line endings.

You can usually find this option refeered to as EOL (End Of Line).

  • Related