🧽
Gitでなるべくストレージ容量を節約したい
Gitでストレージをなるべく節約する。
shallow clone、partial cloneの活用
git clone --depth 1で取得したレポジトリには制約がある。
git clone --depth 1 <URL>
[1]
複数のブランチとタグ情報をclonegit clone --depth 1 --no-single-branch <URL>
過去履歴がほしいとき。
git fetch --depth 100
partial cloneの活用
git fetch --filter=tree:0 --no-recurse-submodules --unshallow
shallow clone解除(全履歴)
全履歴取得なので、ストレージの負担は大きい。
git fetch --unshallow
タグ情報が欲しい時
git fetch --tags
git describe --tagsでタグが見つからず、表示されない場合
git fetch --filter=tree:0 --no-recurse-submodules --unshallow
git fetch --filter=blob:none --no-recurse-submodules --unshallow
git describe --tags
filterを指定しておくと、unshallowで、すべてを取得せず、最低限のみ取得してくれているっぽい。
パーシャルクローン(partial clone)というらしい。[2][3]
--filter=tree:0
--filter=blob:none
mirrorレポジトリでsubmoduleを扱う場合には、partial cloneの利用は、ちょっと注意が必要みたい。
Arch、ManjaroでPKGBUILDのgitソースのストレージ節約
PKGBUILDにgit+httpsなどで、gitレポジトリがソースに指定されている場合、makepkgコマンドで作られるmirrorフォルダは下記gitコマンドと同じ形式で作成される模様。
git clone --mirror URL
容量を節約しつつ、makepkgの作業レポジトリ作成の時間も増やさない手順。
- mirrorを--depth 1でcloneする。
- cloneしたフォルダに移り、
--filter=tree:0
と--unshallow
を指定してfetchする。
git clone --mirror --depth 1 <URL> <REPOSITORY>
cd <REPOSITORY>
git fetch --filter=tree:0 --no-recurse-submodules --unshallow
cd ..
1の手順のみだと、--depth 1
を指定しないcloneと比べて、作業レポジトリのコピーに時間がかかる。
2の手順を行うと、その時間が短縮される。
またclone時にfilterを指定すると、makepkgコマンドで作業コピーが失敗する。
更新がうまくいかない場合に、試すこと。
git remote update --prune
git fetch --depth 1 --refetch --filter=tree:0
git fetch --unshallow --refetch --filter=tree:0
github fork元のタグを取得
upstreamからタグ情報を取得する手順例
git remote add upstream <fork元のリポジトリ>
git fetch upstream --filter=tree:0 --no-recurse-submodules --unshallow
git describe --tags upstream/master
git describe --tags origin/master
git push origin --tags
参考サイト
Git の最新アップデートから考える開発手法の潮流
パーシャルクローンとシャロークローンを活用しよう[3:1]
git リポジトリを clone 後に軽量化する (blobless化)[2:1]
以前forkしたgithubリポジトリを追従させる方法[4]
Github で fork したリポジトリの簡便な同期と運用[5]
Git で shallow clone するときに全ブランチの最新履歴を取得する[1:1]
Discussion