2
0

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でUntracked filesなのに.gitignore効かない時の原因

Posted at

前提

gitignore.ioにてUnity用.gitignoreをインポートしたプロジェクトでの出来事

症状

以下の.csproj.metaファイルがUntracked filesに現れたため.gitignoreに相対フルパスを追記したが反映されなかった。

  • /Assets/Plugins/Zenject/OptionalExtras/ReflectionBaking/Zenject-ReflectionBaking.csproj.meta
  • /Assets/Plugins/Zenject/OptionalExtras/Signals/Zenject\-Signals.csproj.meta

(UnityでZenjectをインポートした際に含まれていたファイルで、.csprojは各環境で生成すれば良いためignoreしていて、同様にUnity内で参照するための.metaファイルもignoreしたという状況。)

原因

上記.gitignore内に以下の記述があったため、そちらの設定が優先されていた

# Never ignore Asset meta data
!/[Aa]ssets/**/*.meta

!は明示的にignoreしないことを示すexcludeの記法

解決方法

Gitでは.gitignoreファイルの記述順で優先度が決まるらしく、上記のexclude記述の後ろに相対フルパスを書いたら無事反映された

最後に

「Git gitignore 効かない」とかでググると一度既にcommitされた歴史があるため$git rm hogeする必要があるよ、みたいな記事ばかりでこの視点にたどり着けなかったため、備忘録として残しておこうと思いました。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?