Github:LF will be replaced by CRLF the next time Git touches it

Github

おつかれさまです。tyamonです。

最近、GitHubを使いこなせるようにいろいろ勉強しています。 今の時代、何をするにもGitは避けて通れないので・・・。そんな中、Windowsで git add をした時に、こんな警告が出てきました。

PS > git add .
warning: in the working copy of '.gitignore', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'eslint.config.js', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'package-lock.json', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'package.json', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'vite.config.ts', LF will be replaced by CRLF the next time Git touches it

今回は、自分への備忘録も兼ねて、この警告がなぜ出るのかサクッとまとめておきます。

なぜ警告が出るの?

これは、WindowsとMac/Linuxで「改行コード」のルールが違うことが原因です。

  • Windows: 改行を CRLF という2文字で表す
  • Mac / Linux: 改行を LF という1文字で表す

GitはLinuxで作られたツールなので、リポジトリの中では LF で統一して保存するのが一般的です。

そこでGitには、「Windowsで使うときは CRLF に、リポジトリに入れるときは LF に」自動で変換してくれる優れものの機能があるそうです。

警告メッセージの正体

今回の警告文、直訳するとこんな感じです。

"warning: LF will be replaced by CRLF the next time Git touches it" 
(警告:次にGitがこのファイルを触る時、LFはCRLFに置き換えられますよ)

要するに、「ちゃんと変換の準備してますよ~」という親切な報告(警告)です。

まとめ

この警告は「GitがWindows用にうまく変換してくれている」という報告(警告)です。

コメント

タイトルとURLをコピーしました