GitBucket4.9がReleaseされています。
ちょうど今のプロジェクトで諸事情あって巨大なバイナリファイルがリポジトリ上に含まれている事情もありGitLFSの導入を検討していた矢先だったので、早速試してみることにしました。
早速GitBucket4.9をここからダウンロードします。
Downloadしたらとりあえずスタンドアローンモードで起動します。
# 実験のため`GITBUCKET_HOME`を別のパスへ差し替え
GITBUCKET_HOME=/tmp/gitbucket4.9 java -jar gitbucket.war
http://localhost:8080して GitBucketにログインし、Base URL
を設定します。
新規リポジトリを作成します。
この時点では、まだlfsディレクトリが作られていません。
$ ls /tmp/gitbucket4.9/repositories/root/
lfs-test.git lfs-test.wiki.git
GitLFSクライアントをインストールしていない場合はインストールしておきます。
# 私はMac
$ brew install git-lfs
$ git-lfs version
git-lfs/1.5.5 (GitHub; darwin amd64; go 1.7.4)
実際にlfsの設定をします。
$ git clone http://localhost:8080/git/root/lfs-test.git
$ cd lfs-test
$ git lfs install
Updated pre-push hook.
Git LFS initialized.
すると、こんな感じに追加されます。
diff --git a/lfs-test/.git/hooks/pre-push b/lfs-test/.git/hooks/pre-push
new file mode 100755
index 0000000..81a9cc6
--- /dev/null
+++ b/lfs-test/.git/hooks/pre-push
@@ -0,0 +1,3 @@
+#!/bin/sh
+command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.\n"; exit 2; }
+git lfs pre-push "$@"
diff --git a/lfs-test2/.git/index b/lfs-test/.git/index
index 4ace396..92f9072 100644
Binary files a/lfs-test2/.git/index and b/lfs-test/.git/index differ
lfsが管理するファイルを設定します(エクセルファイルを駆逐!)。
$ git lfs track "*.xlsx"
Tracking *.xlsx
すると、.gitattributes
が新規に追加されます。
diff --git a/lfs-test/.gitattributes b/lfs-test/.gitattributes
new file mode 100644
index 0000000..ca21a58
--- /dev/null
+++ b/lfs-test/.gitattributes
@@ -0,0 +1 @@
+*.xlsx filter=lfs diff=lfs merge=lfs -text
バイナリファイルを追加します。
$ mv /tmp/test.xlsx ./
$ git add test.xlsx
$ git add .
$ git commit -m "add binary"
$ git push origin master
GITBUCKET_HOME以下を確認するとlfs
ディレクトリが生成され、pushしたxlsxファイルが別に管理されていることがわかります。
$ ls /tmp/gitbucket4.9/repositories/root/lfs-test/lfs/
1fb468ee23d454a1132045dcc1fb85ed9f6729cfdb49c4b6ba3b4eacb2d81d1c
GUI上からもlfsタグが付与された形でポインタが参照されていることがわかります。
試しに/tmp/gitbucket4.9/repositories/root/lfs-test/lfs/1fb468ee23d454a1132045dcc1fb85ed9f6729cfdb49c4b6ba3b4eacb2d81d1c
をExcelで開いてみると正しく開けることがわかります。
別リポジトリしてチェックアウトしてexcelファイルを開いてみると正しく開けることがわかります。
$ git lfs clone http://localhost:8080/git/root/lfs-test.git clone-test
Cloning into 'clone-test'...
remote: Counting objects: 9, done
remote: Finding sources: 100% (9/9)
remote: Getting sizes: 100% (6/6)
remote: Compressing objects: 100% (71/71)
remote: Total 9 (delta 1), reused 6 (delta 0)
Unpacking objects: 100% (9/9), done.
Git LFS: (1 of 1 files) 3.85 KB / 16.87 KB
$ open clone-test/test.xlsx
最後にリポジトリを消してみます。
結果は...残ってますね。
$ ls /tmp/gitbucket4.9/repositories/root/lfs-test/lfs/
1fb468ee23d454a1132045dcc1fb85ed9f6729cfdb49c4b6ba3b4eacb2d81d1c
まぁゴミは残ってしまうようですが、大筋問題なさそうです。
明日会社の環境に適用して人柱になってみようと思います。