Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/squirrel/www/surfrog/web/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340
【10円ゲーム講座】第3回 gitを使ったソースコード管理 | おかしくカエル!

【10円ゲーム講座】第3回 gitを使ったソースコード管理

Git

第3回はGitを使ったソースコード管理についての説明です。
第2回はこちら目次はこちら

ソースコード管理が不要だと思う方やGitに詳しい方はこのページは見なくても大丈夫です。

ソースコード管理はすると便利なので、プロジェクトのソースコードに手を加える前にGitを使ってソースコード管理をします。

HDDやSSDのクラッシュ時のバックアップにもなるので、ソースコード管理をすることは精神に安寧をもたらします。

スポンサーリンク
レクタングル(大)広告

Gitって?

ソースコードの変更を管理するバージョン管理システムの1つです。Linuxカーネルを作ったリーナス・トーバルズ氏が開発したことでも有名です。

早い話がGitを使うことで思いついた機能を即追加、バグが発生したら以前の状態に戻す、といった素早い開発が可能になります。リファクタリングした際のコードもコメントアウトなどで残す必要もなく、コードの肥大化も抑えることができます。

バージョン管理システムはSVNなど色々ありますが、流行にのってGitを使いましょう。

Gitクライアント、TortoiseGitのインストール

Gitのクライアントは何でも良いですが、私はTortoiseSVNを使っていた名残でTortoiseGitを使っています。

TortoiseGitのサイトからダウンロードしてインストールします。

日本語の言語パックがあるので、日本語化したい人は日本語パックもダウンロードしておきましょう。インストールはインストーラーに従って設定するだけでインストールできます。

リポジトリの場所

バックアップを考えたGitソースコード管理では、リポジトリ(gitでバージョン管理するファイル群)を2つ作ることになります。

  1. ローカルで作業をするリポジトリ
  2. ローカル作業の管理先、更新されたファイル群を取ってくるリポジトリ

1.のリポジトリは普段使用する作業用のリポジトリで、ここまでのチュートリアルでCocos2d-xを作成した場所が1.のリポジトリの場所にすると良いでしょう。

2.のリポジトリは1人の場合バックアップにしかならないですが、複数人で開発する際には絶対に必要になるリモートリポジトリと呼ばれるリポジトリです。

私はこのチュートリアルでソースコードを公開するために、Gitを使用するウェブサービス「Github」を使ってリモートリポジトリを置いています。「Github」はリモートリポジトリの置き場所として便利ですが、無料版だと全て公開状態になってしまいます。プライベートなリポジトリが欲しい場合は、GoogleドライブやdropboxなどでGit管理をすると良いでしょう。自分のHDDでもOKですが、耐障害性などを考えるとリモートリポジトリの場所としてはオススメできません。

ここではGoogleドライブを使ったGitソースコード管理について以降で記載します。

Googleドライブのインストール

GoogleドライブでGitを使う場合は、GoogleドライブをコマンドプロンプトやGUI上で扱えるようにインストールします。

Googleドライブのインストール

Googleドライブのメニューから

Googleドライブのインストール

ドライブをダウンロードを選択すると、Googleドライブをインストールできます。

Googleドライブのインストール

エクスプローラからGoogleドライブが見えるようになればインストール完了です。

作業用のローカルリポジトリの作成

Git作業用のローカルリポジトリの作成

「OneCoinGame」はD:\workspaceにプロジェクトを作成したので、D:\workspaceの「OneCoinGame」フォルダをローカルリポジトリにします。

Git作業用のローカルリポジトリの作成

プロジェクトを選択して、「Git ここにリポジトリを作成」を実行します。

Git作業用のローカルリポジトリの作成

Bare を生成のチェックを外します。Bareリポジトリとは、作業用のファイルを持たない管理用のリポジトリのことです。

OKを押すと、OneCoinGameフォルダ以下がリポジトリになり、内部に.gitフォルダ(隠しフォルダなので設定によっては見えません)が出来ます。

Git作業用のローカルリポジトリの作成

リポジトリは出来ましたが、まだプロジェクトが管理対象になっていません。フォルダやファイルを管理対象に追加することで、バージョン管理ができるようになります。

Git作業用のローカルリポジトリの作成

.gitフォルダ以外の全てのフォルダ・ファイルを選択し、右クリックのTortoiseGitのメニューから「追加」を選択します。

Git作業用のローカルリポジトリの作成

「すべてを選択/解除」を選び、ファイルを全て追加します。Visual Studioでビルドして実行している場合は、テンポラリ系のファイルが入っているため、一度クリーンしてから追加することをオススメします。

OKを押すとフォルダやファイルがリポジトリの管理対象になります。管理対象になっただけで、まだ実際に追加されているわけではありません。

Git作業用のローカルリポジトリの作成

実際にファイルを追加するためにコミットを行います。右クリックメニューから「Git コミット」を実行します。

Git作業用のローカルリポジトリの作成

新たに追加したファイルしか無いため、変更した項目は全ファイルが出てきます。今回のコミットに対するメッセージを入力して、OKを押します。

Git作業用のローカルリポジトリの作成

成功と出ればコミット完了です。ローカルリポジトリを作成することが出来ました。

Googleドライブ上にリモートリポジトリを作成する

Gitリモートリポジトリの作成

(何も選択していない状態で)右クリックのTortoiseGitメニュー→Git クローン(複製)」を選択します。

Gitリモートリポジトリの作成

URL:には、ローカルリポジトリのパスを(D:\workspace\OneCoinGame)を入力します。

ディレクトリはリモートリポジトリを置く場所を指定します。ここでGoogleドライブのパスを入力することでGoogleドライブ上にリモートリポジトリを作成することができます。また、リポジトリ名は.gitを付けることが通例なのでOneCoinGame.gitとしました。

リモートリポジトリは管理用のリポジトリのため、「Bareリポジトリにクローン」にチェックを入れます。

Gitリモートリポジトリの作成

OKを押すとGitのクローンが作成されます。このクローンがリモートリポジトリになります。

ローカルリポジトリからリモートリポジトリにプッシュする

Gitローカルからリモートへのプッシュ

ローカルリポジトリを選択して、右クリックTortoiseGitメニューから「プッシュ(リモートへ反映)」を選択します。

Gitローカルからリモートへのプッシュ

このままではリモート欄が空白なのでプッシュできないので、管理を選択します。

Gitローカルからリモートへのプッシュ

リモートのURL:に、Google ドライブのリモートリポジトリのパスを入力してOK

Gitローカルからリモートへのプッシュ

リモート欄がoriginになっていることを確認してOKを押します。

Gitローカルからリモートへのプッシュ

成功するとローカルリポジトリからリモートリポジトリにプッシュ完了です。

ローカルリポジトリのデータが無くなった場合

SSDやHDDといったローカルなドライブに格納されたデータは消えるものです。ローカルリポジトリが消えた時のことを想定して、復帰を行ってみます。

Gitクローン操作

D:\workspaceのOneCoinGameを削除します。これでローカルリポジトリが何らかのアクシデントにより消えてしまったと仮定しましょう。

Gitクローン

ローカルリポジトリを作成したい場所で、右クリック→TortoiseGitメニューからGitクローン(複製)」を選択します。

Gitクローン操作

URL:にGoogleドライブのリモートリポジトリのパスを指定します。作業用なので「Bareリポジトリにクローン」のチェックは外しておきます

Gitクローン操作

OKを押すとローカルリポジトリが作成されます。

Gitクローンで作成したファイル

ファイル構成を見て、ビルドもしてみると良いでしょう。

ビルド結果

リモートリポジトリからローカルリポジトリがすぐに複製(クローン)できました。

今回はリモートリポジトリをGoogleドライブにしているので非常に安心です。地球規模の大災害が起きない限りデータは守られていることでしょう。

ちなみにリモートリポジトリの方が万一消えても、ローカルリモートリポジトリから復帰できるのが、分散型バージョン管理システムであるGitの良いところでもあります。とはいえ、Googleが管理しているサーバーのデータが消えて自分のPCが生きているというのは想像できません。

Gitの運用

ここまででGitを使ったソースコード管理の準備ができました。後は開発して運用していくだけです。

ファイルの変更

Gitコミット

Gitローカルからリモートへのプッシュ

ローカルリポジトリに変更をコミットして、プッシュでリモートリポジトリへ反映します。

ファイルの追加

Git作業用のローカルリポジトリの作成

Gitコミット

Gitローカルからリモートへのプッシュ

プロジェクトに追加したファイルは、TortoiseGitのメニューの「追加」を選び管理対象に追加ます。その後はファイルの変更と同じく、ローカルリポジトリに変更をコミットして、プッシュでリモートリポジトリへ反映します。

ログを表示

Gitログ表示

TortoiseGitのメニューの「ログを表示」で、これまでのコミット内容を表示できます。

Gitログ表示

コミットの状況を確認できます。例えば、最初のコミット時に「ソースコード管理の開始」と入力したことが確認できます。

差分

Git差分

右クリックTortoiseGitメニューから「差分」を選ぶことで、コミットした内容と現在の内容の差分が表示できます。コミット前の最終確認などに利用すると良いでしょう。

後は運用しながら色々使ってみて下さい

ブランチの作成などGitは1冊の本が書けるぐらいには色々できます。運用しながら色々弄ってみると良いでしょう。

補足:Visual StudioとGit

Visual StudioからGitの変更を確認することができます。

GitとVisual Studio

ファイルを右クリック→履歴の表示

GitとVisual Studio

そのファイルの履歴を確認することができます。

補足:Gitでデザインデータも管理する

デザインデータもGitで管理すると便利です。

ソースコード管理として開発されたGitですが、現在では画像や動画などの大容量サイズの取り扱いもできるので、デザインデータも管理対象にしておくと便利です。

Gitデザインデータ

私もPhotoshopのデータなどもGitの管理対象にしています。

Gitデザインデータ

ゲームなどではシートデータなども作ることが多いので、これらもまるっと管理対象にしても便利です。さらには設計書なども適宜やってしまっても良いでしょう。

次回は10円ゲームの進め方と最初の変更です。

スポンサーリンク
レクタングル(大)広告
レクタングル(大)広告

シェアする

  • このエントリーをはてなブックマークに追加

フォローする