31
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gitで差分が出続ける現象の解決法

Last updated at Posted at 2015-03-02

gitで差分が出続ける時がある。

$git status

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   app/hoge.php

no changes added to commit (use "git add" and/or "git commit -a")

commitしてもstashしてもresetしても出続ける。SourceTreeやGitHubのGUIで実行しても同じ。なにこの悪夢。

addしてみたら以下のwarningが出た

$ git add app/hoge.php
warning: LF will be replaced by CRLF in app/hoge.php

原因

Git が改行コードを CRLF へ勝手に変更しようとするらしい。

解決方法

addの前に以下のコマンドを打てばOK。改行コードの自動変換をしなくなる設定に。

$ git config --global core.autoCRLF false

補足

上記コマンドにより.gitconfigファイルでもともとtrueだった以下の設定がfalseになる。

gitconfig
core.autoCRLF=false

というわけで、

$ git config --global core.autoCRLF false
$ git add app/hoge.php
$ git commit -m "piyopiyo"

これで無事コミットできた。

31
32
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?