World map

 

BM: Baca dalam Bahasa Melayu

World 11: Rescue Center

Windows line-ending chaos

You will learn: how one .gitattributes file calms line-ending chaos for everyone.

The problem

Mei fixed one typo on Windows. But git diff says every line changed! Why?

Pick one answer.

This happens to everyone. Here’s the calm way out.

Watch

Every line ends with an invisible line ending. Windows uses two marks: CRLF. Mac and Linux use one: LF. Sort them.

Drag a card into a box. Or tap the card, then tap the box.

      Try it

      One file fixes it for the whole team. Make .gitattributes with * text=auto. Then commit it.

      Working folder
      • Empty
      Staging area
      • Empty
      Repository
      • 3 save points
      • Add style
      • Add day 1 page
      • Add README

      Watch

      bash
      git add --renormalize .
      git commit -m "Normalize all the line endings"
      Two commands: git add --renormalize dot, then git commit -m Normalize all the line endings.

      Old files may still have the old endings. git add --renormalize . re-adds every tracked file with the new rule. Then commit once.

      Try it

      Each person can set a helper too. Build the Windows setting.

      Tap the pieces in the right order.

      …

      Predict

      Why commit .gitattributes, not just tell everyone the setting?

      Pick one answer.

      You did it!

      You can now calm line-ending chaos for the whole team.

      Go deeper (optional)

      Scripts that must keep LF? Add *.sh text eol=lf. Windows-only files? *.bat text eol=crlf. Mark pictures as binary so Git never touches them. Run git add --renormalize . from a clean working folder. GitHub Docs has a full guide.