TortoiseGit Godot4アセットをサブモジュールとして追加コミット

Git をエクスプローラで操作できるクライアントソフト TortoiseGit でプロジェクトに追加したサブモジュールコミットする手順を紹介します。
コミット前後の git status コマンドによる変更点・ステージングエリアの状態の確認結果や、コミット時のサブモジュールのフォルダの create mode についても紹介します。

TortoiseGit ダウンロードとインストール1

※ TortoiseGit-2.17.0.2-64bit を使用します。

前回の記事

前回は、GodotEngine4 のユニットテスト用アセット GUTTortoiseGit を用いて Git サブモジュールとして作業ディレクトリに配置しました。

TortoiseGit 作業ディレクトリにGodot4用サブモジュールを追加 | Compota-Soft-Press

サブモジュールの追加は、 git submodule add コマンドで行えます。

Inspects, updates and manages submodules.

サブモジュールを検査、更新、管理します。

add
Add the given repository as a submodule at the given path to the changeset to be committed next to the current project: the current project is termed the “superproject”.

指定されたリポジトリを、現在のプロジェクトの次にコミットされる変更セットへの指定されたパスにあるサブモジュールとして追加します。現在のプロジェクトは「スーパープロジェクト」と呼ばれます。

Git – git-submodule Documentation と Google 翻訳

サブモジュールの Git 管理追加とステージングエリアの確認

サブモジュールを配置した際に作成された

  • .gitmodules
    ※プロジェクトに配置した全てのサブモジュールの情報を記述したファイルです。
  • third_party/Gut
    ※サブモジュールを配置したフォルダパスです。

2つの項目をそれぞれ、作業ディレクトリを開いたエクスプローラで選択してから、右クリックして表示されるメニュー「TortoiseGit」→「追加」で表示される追加のダイアログOK ボタンを押して、コミット対象のステージングエリアに追加しました。

以下はその時点でのステージングエリアの状態を git status コマンドで確認したものです。

G:\Dev\Godot4GD\SakuraCrowd\SakuraCrowdGodotLib>git status
On branch develop
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   .gitmodules
        new file:   third_party/Gut

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
        modified:   third_party/Gut (modified content)

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        addons/
        export_presets.cfg
        icon.svg
        icon.svg.import
        project.godot
        resource/
        scene/
        third_party/.gdignore

Displays paths that have differences between the index file and the current HEAD commit, paths that have differences between the working tree and the index file, and paths in the working tree that are not tracked by Git (and are not ignored by gitignore[5]). The first are what you would commit by running git commit; the second and third are what you could commit by running git add before running git commit.

インデックス ファイルと現在の HEAD コミットの間に差異があるパス、作業ツリーとインデックス ファイルの間に差異があるパス、Git によって追跡されない (そして gitignore[5] によって無視されない) 作業ツリー内のパスを表示します。 1 つ目は、git commit を実行してコミットするものです。 2 番目と 3 番目は、git commit を実行する前に git add を実行することでコミットできるものです。

Git – git-status Documentation と Google 翻訳

12 行目を見ると、ステージングされていない変更点 (Changes not staged for commit) にも third_party/Gut が表示されていますが、これは Gut サブモジュール内の変更を指しています。

サブモジュール内の変更は、操作しているプロジェクトとは別の管理となるため、コミット対象のステージングエリアには追加されないからと考えられます。

サブモジュールを使うと、ある Git リポジトリを別の Git リポジトリのサブディレクトリとして扱うことができるようになります。 これで、別のリポジトリをプロジェクト内にクローンしても自分のコミットは別管理とすることができるようになります。

Git – サブモジュール

GodotEngine4 エディタで開いた際の Gut アドオンの警告を解消するために、Gut サブモジュール内を変更したことについては以下の記事を参照してください。

追加したサブモジュールの情報をコミット

前の章では、.gitmodules ファイルとサブモジュールのフォルダをステージングエリアに追加しました。

次に、.gitmodules ファイルとサブモジュールのフォルダ(リンク先)をコミットします。

作業ディレクトリを開いたエクスプローラで右クリックで表示されるメニュー「Git コミット -> “ブランチ名”」を選択して、コミットのダイアログを開きます。

下側の Changes made リストに、.gitmodules ファイルとサブモジュールのフォルダパスチェックされていることを確認して、コミットのメッセージを入力して「コミット」ボタンを押します。

git submodule で追加した Godot4 Gut アセットを追加・コミット1

サブモジュール内の変更をコミットする必要があるかをたずねるダイアログが表示されました。

サブモジュール内の変更については、後でサブモジュールをコミットするので、今回は「無視」を選択します。
※次の小さな章で述べる通り、無視をせずに、サブモジュール自体のコミットも後で行いました。

git submodule で追加した Godot4 Gut アセットを追加・コミット2

[Window Title]
TortoiseGit

[Content]
サブモジュール “third_party/Gut” にコミットしていない変更があります。サブモジュールの変更をコミットしないと、親プロジェクトはこの変更を記録できません。サブモジュールへコミットしますか? それとも、この変更を無視しますか?

[コミット] [無視(I)] [キャンセル]

サブモジュールの変更を無視するのは問題

ローカルのサブモジュール内に差分があると、他の環境と異なる状態になるため良くないと判断します。
そのため、このあと、そのサブモジュール内の変更は、GUT リポジトリからフォークしたリモートリポジトリにプッシュして、そのフォークしたリモートリポジトリを参照するように変更しました。

それについては以下の記事を参照してください。

コミット結果の確認

コミットが実行されました。
サブモジュールのフォルダパス third_party/Gut もコミットされました。

git submodule で追加した Godot4 Gut アセットを追加・コミット3
create mode 160000 third_party/Gut

create mode の 160000 はサブモジュールを指します。

DbConnector エントリのモードが 160000 となったことに注目しましょう。 これは Git における特別なモードで、サブディレクトリやファイルではなくディレクトリエントリとしてこのコミットを記録したことを意味します。

Git – サブモジュール

注目すべきは出力された1列目の数字です。この数字はモードビットと呼ばれ、ビット列の前半部分がファイル種別を、後半部分がパーミッションを表します。

主なモードビットの一覧:

  • 100644 (1000000110100100): 実行不可能な通常ファイル
  • 100755 (1000000111101101): 実行可能な通常ファイル
  • 040000 (0100000000000000): ディレクトリ
  • 120000 (1010000000000000): Symbolic link
  • 160000 (1110000000000000): Gitlink (Submodule)
巨大な Git submodule のバージョンを一瞬で更新する方法 #Git – Qiita

コミット後にもう一度 git status コマンドを実行するとステージングされていた .gitmodules ファイルとリンク先の third_party/Gut フォルダのリンク先情報がコミットされ、コミット候補のステージングエリアから消えました。

G:\Dev\Godot4GD\SakuraCrowd\SakuraCrowdGodotLib>git status
On branch develop
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
        modified:   third_party/Gut (modified content)

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        addons/
        export_presets.cfg
        icon.svg
        icon.svg.import
        project.godot
        resource/
        scene/
        third_party/.gdignore

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

まとめ

今回は、 Git をエクスプローラで操作できるクライアントソフト TortoiseGit でプロジェクトに追加したサブモジュールコミットする手順を紹介しました。
コミット前後の git status コマンドによる変更点・ステージングエリアの状態の確認結果や、コミット時のサブモジュールのフォルダの create mode についても紹介しました。

参照サイト Thank You!

記事一覧 → Compota-Soft-Press

コメント

Ads Blocker Image Powered by Code Help Pro

お願い - Ads Blocker Detected

このサイトは広告を掲載して運営しています。

ポップアップを閉じて閲覧できますが、よろしければ

このサイト内の広告を非表示にする拡張機能をオフにしていただけませんか?

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

タイトルとURLをコピーしました