LoginSignup
9
1

More than 3 years have passed since last update.

MATLABでGitを操作しよう (第4回 : ブランチ作成)

Posted at

引き続きMATLAB GUIによるGit操作の第4回目

作成環境 MATLAB R2019b

第1回 : プロジェクト作成とGUIの説明
第2回 : git add/git commit
第3回 : チェックアウト "特定のコミットに戻る"
第4回 : ブランチ作成
第5回 : リモートリポジトリとの連携 (git push/git pull)
第6回 : クローンを作成する
第7回 : 応用1
第8回 : 応用2

ブランチ作成

前回までのプロジェクトには、foo.mとgoofy.mというファイルがGitの管理下であり、プロジェクトの管理対象でした。そこで、次は新しい機能としてsloth.mを別ブランチの中で作っていきます。
図で示すと以下の様になります。

git4_2.png

ブランチの作成手順

  1. ブランチボタンをクリック
  2. ブランチ ダイアログの「ブランチとタグの作成」をクリック
  3. 新規 「ブランチ」を選択
  4. 名前欄に任意のブランチ名を設定 (今回はfeature_1)
  5. 「作成」ボタンをクリック git4_3.png

新規ブランチで開発

プロジェクトウィンドウで「現在のブランチ」がfeature_1となっていることを確認します。
sloth.mを「プロジェクトに追加」します。第1回でも説明したように、この操作はgit addに相当します。
git4_4.png

ファイル編集

fearture_1ブランチにて
sloth.mを1回編集し、コミットします
git4_5.png

masterブランチにチェックアウト

ブランチボタンをクリックし、masterブランチにチェックアウト(切り替え)します。
sloth.mはmasterブランチから切り離されたブランチで開発されているので、フォルダから見えなくなります。
git4_7.png

ブランチ状態の確認

ブランチボタンをクリックし、ブランチとして「すべて」を選択します。すると、feature_1ブランチが分岐し、sloth.mがコミットされていることがわかります。
git4_8.png

ブランチのMerge

sloth.mの開発が完了したと仮定し、master <= feature_1にMergeします。
1. ブランチでmasterを選択し、「切り替え」をクリック
2. 現在のブランチの名前がmasterになっていることを確認
3. 「マージ」ボタンをクリック
git4_9.png

ブランチのMerge 完了

「マージ」ボタンをクリックすると、分岐していたfeature_1がmasterに接続されたことがわかります。
git4_10.png

プロジェクトAPI紹介

ここまでで今回の記事は終了ですが、関連APIとしてを1つ紹介します。
新規追加したsloth.mのファイルステータスを取得してみたいと思います。
プロジェクト管理下では、「プロジェクトオブジェクト」というオブジェクトで管理下のファイルステータスや、バージョン管理ツールとの連携状況を見ることが出来ます。
オブジェクトの返り値をmyPrjとすると

myPrj = currentProject
myPrj = 

  Project のプロパティ:

                        Name: "gitPrj1"
    SourceControlIntegration: "Git"
          RepositoryLocation: "リモート origin が指定されていません;"
       SourceControlMessages: [1×3 string]
                    ReadOnly: 0
                    TopLevel: 1
                Dependencies: [1×1 digraph]
                  Categories: [1×1 matlab.project.Category]
                       Files: [1×3 matlab.project.ProjectFile]
                   Shortcuts: [1×0 matlab.project.Shortcut]
                 ProjectPath: [1×1 matlab.project.PathFolder]
           ProjectReferences: [1×0 matlab.project.ProjectReference]
                StartupFiles: [1×0 string]
               ShutdownFiles: [1×0 string]
                 Description: ""
                  RootFolder: "T:\Qiita\gitPrj1"
         SimulinkCacheFolder: ""
       SimulinkCodeGenFolder: ""
        ProjectStartupFolder: "T:\Qiita\gitPrj1"
myPrj.Files(3)

ans = 

  ProjectFile のプロパティ:

                   Path: "T:\Qiita\gitPrj1\sloth.m"
                 Labels: [1×1 matlab.project.Label]
               Revision: ""
    SourceControlStatus: Unmodified

と言った具合に、sloth.mは変更されていない事がプロジェクトオブジェクトのプロパティ値から判定ができます。

APIドキュメント
currentProject

9
1
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
9
1