LoginSignup
0
0

More than 3 years have passed since last update.

Androidアプリ開発探求記(その4)

Posted at

概要

今回は git の .ignore に関して、探求してみたいと思います。

やること

Android Studio で作成したデフォルトの .ignore ファイルに対して、以下のことをしてみようと思います。

  • 現在の実験コード1上にフィルタリング対象が存在する項目に対してコメントを追加
  • 現在の実験コード上にフィルタリング対象が存在しない項目を削除

※ 自明と思われるものについては例外的に .ignore に含めていこうと思います。2

背景

.ignore に関してはネット上に様々な情報が存在し、.ignore.io のような便利な自動生成ツールも存在します。

しかし、状況によっては必要となるグレーゾーンのファイルまでバッサリ切り捨ててしまっているため、弊害もあります。

例えば、開発プロジェクトでスペルチェック用辞書を共有する方法では辞書ファイルは idea/dictionaries フォルダ以下に配置されますが、.gitignore.io [AndroidStudio] ではバッサリ切り捨てられてしまっています。

実際問題としては、Android Studio 上での辞書共有にはいろいろと欠点もあるため、デフォルトでバッサリ切り捨ててしまったほうが安全だと思います。しかし、最初から切り捨ててしまうと、存在自体を気づけないという弊害があり、これは探求記的には許容できません。

ということで、今後 .ignore に関しては、全項目を把握していこうと思います。

Android Project

Android Studio で作成したデフォルトの .ignore ファイルは2つあります。

◆ Root Project

/build

◆ Sub Project

*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx

.gitignore を削除してみる

.gitignore を削除し、Reimport gradle project, Rebuild Project を行い、差分を確認してみます。

$ git status
On branch comment_on_dot_ignore_files
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    .gitignore
        deleted:    app/.gitignore

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gradle/
        .idea/caches/
        .idea/libraries/
        .idea/modules.xml
        .idea/modules/
        .idea/workspace.xml
        app/build/
        local.properties

必須の項目だけ復活させる

現状でフィルタが必要、もしくは自明の項目だけを復活させてみます。

### Android Studio ###

# IDEAのモジュール定義ファイル。自動生成されるものなので、commit されるべきではない。
*.iml

# IDEローカルのキャッシュ情報だと思われる。commit されるべきではない。
/.idea/caches

# IDE上で利用されるライブラリの情報だと思われる。自動制裁される情報であり、共有の必要もないので、commit されるべきではない。
/.idea/libraries

# IDE上のモジュール構成情報だと思われる。IDEの利用状況により異なる情報であり、共有の必要もないので、commit されるべきではない。
/.idea/modules.xml

# IDEローカルの情報なので commit されるべきではない。
/.idea/workspace.xml

# This file is automatically generated by Android Studio. This file should *NOT* be checked into Version Control Systems, as it contains information specific to your local configuration.
/local.properties

### Gradle ###

# gradle の work 領域。gradle により自動生成されるものなので commit されるべきではない。
.gradle

# gradle の build 成果物用フォルダ。build により自動生成されるものなので commit されるべきではない。
/build

### MAC ###

# MAC OS上の不可視ファイル。commit されるべきではない。
.DS_Store

削除された項目

/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/captures
.externalNativeBuild
.cxx

まとめ

今回は、Android Studio で作成したデフォルトの .ignore ファイルに対して、現時点で必須なものだけに対してコメントを付与し、そうでないものは削除してみました。

今後も同様の対応をしていこうと思います。

0
0
1

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