shuhelohelo’s blog

Xamarin.Forms多めです.

GitHubから特定のフォルダをダウンロードする

GitHub上のあるリポジトリの中の任意のサンプルプロジェクトだけ取得したい場合が多々あります。

これまでは1つのサンプルプロジェクトを取得するためにリポジトリ全体をcloneしていました。 これは実際時間的にも容量的にもかなり無駄が多くなんとかならないかなと思いました。

調べてみると、GitHubSubversionでexportする機能を使うことでディレクトリ単位でソースコードを取得できることがわかりました。

blog.clock-up.jp

Windowsの場合、まずはSubversionのクライアントをインストールする必要があります。

環境

  • Windows10 Pro 1903

Subversionクライアントのインストール

いくつかあるようですが、今回はなんとなく目についたSlikSVNというクライアントを選びました。

こちらからダウンロードします。

sliksvn.com

zipを解凍して中のmsi形式のインストーラを実行し、案内に従ってインストールを完了します。

インストール後の確認

インストールされたかコマンドラインから確認してみましょう。

コマンドプロンプトPowerShellなどのコマンドラインを起動し、svn --versionを実行します。

C:\Users\hoge>svn --version
svn, version 1.12.0-SlikSvn (SlikSvn/1.12.0)
   compiled May 28 2019, 13:44:56 on x86_64-microsoft-windows6.2.9200

Copyright (C) 2019 The Apache Software Foundation.
This software consists of contributions made by many people;
see the NOTICE file for more information.
Subversion is open source software, see http://subversion.apache.org/

バージョン情報が表示されればOKです。

GitHubからディレクトリのダウンロード

では、今回取得したいディレクトリは以下のディレクトリです。

github.com

これはXamarinというリポジトリ内のXamarinComponents/Android/ARCore/samples/ディレクトリです。

このサンプルプロジェクトだけ取得してみます。

masterブランチから取得する場合

svnを使ってダウンロードする場合、対象のURLを一部書き換える必要があります。

元:
https://github.com/xamarin/XamarinComponents/tree/master/Android/ARCore/samples
↓
後:
https://github.com/xamarin/XamarinComponents/trunk/Android/ARCore/samples

tree/masterの部分をtrunkに変更します。

このURLを使ってsvnコマンドでダウンロードします。 svn export https://github.com/xamarin/XamarinComponents/trunk/Android/ARCore/samples

コマンドを実行したディレクトリに対象のディレクトリ(この場合だとsamples)がダウンロードされます。

C:\Users\hoge>svn export https://github.com/xamarin/XamarinComponents/trunk/Android/ARCore/samples
A    samples
A    samples\HelloAR.sln
A    samples\HelloAR
A    samples\HelloAR\Assets
A    samples\HelloAR\Assets\andy.obj
...

master以外のブランチから取得する場合

masterブランチではtree/mastertrunkと変えましたが、treebranchesに変えます。

元:
https://github.com/xamarin/XamarinComponents/tree/google-billing-android/Android/ARCore/samples
↓
後:
https://github.com/xamarin/XamarinComponents/branches/google-billing-android/Android/ARCore/samples

同様に以下のようにsvn exportコマンドでダウンロードします。

svn export https://github.com/xamarin/XamarinComponents/branches/google-billing-android/Android/ARCore/samples

C:\Users\shuhey>svn export https://github.com/xamarin/XamarinComponents/branches/google-billing-android/Android/ARCore/samples
A    samples
A    samples\HelloAR.sln
A    samples\HelloAR
A    samples\HelloAR\Assets
A    samples\HelloAR\Assets\andy.obj
...