【Git】.gitignore の状態を確認するコマンドたち

git status --ignored

まずは、状態の確認をしましょう。

以下は、基本的な Android プロジェクトでの例。


 

■ 位置を確認する


❯ find . -name .gitignore                          
./app/.gitignore
./.gitignore
./.idea/.gitignore

👉 AndroidStudio 新規プロジェクトテンプレートから考える .gitignore hatena-bookmark

 

■ git status


❯ git status          
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

 

■ git status --ignored


❯ git status --ignored
On branch main
Your branch is up to date with 'origin/main'.

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

nothing to commit, working tree clean

→ ignore 対象が確認できます。

 

■ git clean -ndX


❯ git clean -ndX
Would remove .gradle/
Would remove .idea/workspace.xml
Would remove app/build/
Would remove build/
Would remove local.properties

 

■ git check-ignore -v


❯ git check-ignore -v .gradle/           
.gitignore:2:.gradle    .gradle/

❯ git check-ignore -v .idea/workspace.xml
.idea/.gitignore:3:/workspace.xml       .idea/workspace.xml

❯ git check-ignore -v app/build/         
app/.gitignore:1:/build app/build/

❯ git check-ignore -v local.properties
.gitignore:15:local.properties  local.properties

❯ git check-ignore -v **/*
app/.gitignore:1:/build app/build
app/.gitignore:1:/build app/build/generated
app/.gitignore:1:/build app/build/generated/ap_generated_sources
app/.gitignore:1:/build app/build/generated/ap_generated_sources/debug
app/.gitignore:1:/build app/build/generated/ap_generated_sources/debug/out
app/.gitignore:1:/build app/build/generated/res
...

→ そのファイルを ignore するパターン記述を特定することができます。

 

■ git ls-files --other --ignored --exclude-standard


❯ git ls-files --other --ignored --exclude-standard
.gradle/7.5.1/checksums/checksums.lock
.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock
.gradle/7.5.1/dependencies-accessors/gc.properties
.gradle/7.5.1/executionHistory/executionHistory.bin
.gradle/7.5.1/executionHistory/executionHistory.lock
...

→ 実際に ignore されたファイル一覧が確認できます。Adroid プロジェクトでは出力行が多くなるので省略しています。

 

■ 参考

👉 Git のステータス: リポジトリの検査 | Atlassian Git Tutorial hatena-bookmark


Rename Git branch master to main


❯ git -v
git version 2.39.1

 

■ Delete local branch


git branch -d master

 

■ Rename local branch


git branch -m master main

 

■ Push the new branch, set local branch to track the new remote


git push -u origin main


git push --set-upstream origin main

 

■ Delete remote branch


git push origin :master


git push origin --delete master

I got this.


❯ git push origin :master
To https://github.com/your/project
 ! [remote rejected] master (refusing to delete the current branch: refs/heads/master)
error: failed to push some refs to 'https://github.com/your/project'

Switch default branch master to main at https://github.com/your/project

Rename Git branch master to main

 

■ Show status


❯ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean

❯ git branch -a
* main
  remotes/origin/main

❯ git branch -l
* main

❯ git branch -r
  origin/main

 

■ Conclusion



Repository default branch
Choose the default branch for your new personal repositories. You might want to change the default name due to different workflows, or because your integrations still require “master” as the default branch name. You can always change the default branch name on individual repositories.


👉 GitHub - Settings - Repositories hatena-bookmark

👉 Managing remote repositories - GitHub Docs hatena-bookmark


Android Studio Electric Eel | 2022.1.1 の JDK11 設定

一番標準的で簡単な Android Studio Electric Eel での JDK設定です。

メニューから About Android Studio で表示される内容は以下。

Build #AI-221.6008.13.2211.9477386, built on January 11, 2023


Android Studio Electric Eel | 2022.1.1
Build #AI-221.6008.13.2211.9477386, built on January 11, 2023
Runtime version: 11.0.15+0-b2043.56-8887301 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 13.1
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 16
Registry:
    external.system.auto.import.disabled=true
    ide.text.editor.with.preview.show.floating.toolbar=false
    documentation.show.toolbar=true

Non-Bundled Plugins:
    org.moe (1.5.2)
    org.jetbrains.compose.desktop.ide (1.2.2)
    com.jetbrains.kmm (0.5.1(221)-61)

表示されてるように Android Studio に同梱されてる JDK は OpenJDK 11.0.15 改 by JetBrains という感じでしょうか。

公式 developers.android.com には以下のように書かれています。


なので、この Android Studio に同梱された JDK を使う設定をします。

メニューから、


Settings...

  ↓

Build, Execution, Deployment

  ↓

Build Tool

  ↓

Gradle

Embedded JDK version 11.0.15 を選択します。

Android Studio Electric Eel | 2022.1.1  での JDK設定

あとは、build.gradle に以下を記述しておきます。


  compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
  }

  kotlinOptions {
    jvmTarget = JavaVersion.VERSION_11.toString()
  }

以上です。

これが、きっと今現在では最も標準的で簡単です。

👉 【Android Studio】Settings - Build Tools - Gradle JDK の選択肢がゴミだらけで意味不明の場合 hatena-bookmark
👉 AndroidStudio 利用する Java (JDK) の選択・設定の方法 hatena-bookmark