LoginSignup
3
2

More than 5 years have passed since last update.

git clone直後に、何もしていないのにdiffが発生しつづける問題

Last updated at Posted at 2018-03-19

発生環境:MacOS Sierra 10.12.6
※今回OSは特に関係なかった

結論を急ぐ場合は 真の原因

なにがおきたか

しばらく触っていなかったgithub上のプロジェクトのlocal repositoryを、masterの最新にしようとして

$ git checkout master
$ git pull
$ git status

すると

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

    deleted:    {the_file_in_trouble}

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

と。
あれ? masterブランチでなんか作業しちゃったかなー?

$ git reset --hard origin/master

remoteのmasterに強制一致コマンドを実施。

$ git status
On branch {branch_name}
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:   {the_file_in_trouble}

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

???
今合わせたよね?
しばらくしてもう一度やってみると

$ git status
On branch {branch_name}
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    deleted:    {the_file_in_trouble}

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

あれ、modified から deletedになっている。
かくなる上は、一旦全リセット。
※localの変更全部消えるので実行注意

$ cd ..
$ rm -rf {repository_name}
$ git clone {clone_with_ssh_uri}

よし、全部キレイになったはず。

$ cd {repository_name}
$ git status
On branch {branch_name}
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    deleted:    {the_file_in_trouble}

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

のおーー?リセットしたのに何か履歴が残ってるの?

その後、gitのglobal設定(~/.gitconfig, ~/.gitignore_global)などを確認してみるも、怪しい設定なし。

あやしいせん

git ゾンビ git rm できない git clone 履歴が残る などでぐぐってみる。
こんな記事が見つかった。

この記事によると、ファイルシステムの大文字小文字を区別するかしないか、の設定が原因になることがあるらしい。
他の開発者が大文字小文字を区別する環境で、同じ名前のファイルをコミットすると発生するようだ。
自分の開発環境がまさに「Mac OS 拡張 (ジャーナリング)」(大文字小文字区別しない)で、他の開発者が皆 Ubuntu/CentOS on Windows だったので、条件にぴったり一致していそう。
記載してある手順で大文字小文字を区別するイメージを作成・マウントし、そこに git clone してみた。

$ cd /Volume/GitData
$ git clone {clone_with_ssh_uri}

よし

$ cd {repository_name}
$ git status
  ~略~
    deleted:    {the_file_in_trouble}
  ~略~

あれ、なおらない。。。

真の原因と対策

何度もトライしているうちに、あることに気づいた。
いつも「あなたのPCは守られているわ!」とか「サーバーへの接続に失敗しました」とちらちら画面右上あたりでNotificationを飛ばしてくる、ウイルスソフト、
なんかいつもと違うこと言ってる気がする・・・!

疑わしいトロイの木馬を検知しました。Path/Paht/Path/

なにー!トロイの木馬認定されてる・・・!
そしてしばらく経過後、

次の脅威のため隔離されました。

あー、隔離されちゃって。だから差分が出ちゃってたのか。modifiedとか、時々出ていた PermissionDeny 系は、きっと隔離する前に保護されてたのね。
納得。
ちなみに、問題のファイルの中身を検証したところ、filetypeやサイズに異常なところはなく、
dynamo-localをwgetで取ってくるだけの簡単な一文が引っかかっていた様子。
どこかのトロイの木馬系ウィルスとパターンがマッチしちゃったのでしょうか・・・。

気を取り直して、以下対策。

  1. 対象のファイルを確認、問題のないファイルであることをしっかりチェック
  2. 再度 $ git reset --hard origin/master を実施、ウィルスを検知されたら素早く対策ソフトを確認して「無視」などの措置を実施
  3. ウィルス対策ソフトの環境設定で、対象のファイルをスキャンの「除外リスト」に追加

※ 2,3 は一旦ウィルスソフトを停止させて実施しても良い

ちなみにウィルスソフトはカスペルスキーでした。

教訓:いつもなんやかんや言ってくるウィルスソフト、空気のような存在になっちゃいがちだけど、たまにはなんて言ってるか確認しよう。

3
2
0

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
3
2