6
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Gitlabでlfs

Last updated at Posted at 2016-09-03

せっかくのGitlab8系

前回Gitlabを8系までアップグレードしたので以前にはなかった機能でlfsが8.2から使用できるらしい。これはバイナリファイルが別に管理されリポジトリが重くならないというものらしい。

インストール

まずはクライアント側にlfsをインストール
自分は大抵クライアント側はMacなのでbrewでインストール

$ brew update
$ brew install git-lfs

エラー

git 管理のフォルダに移って早速バイナリファイルを作ってpushしてみる。

$ git lfs install
$ git lfs track "*.zip"
$ zip -9 README.zip README.md
$ git add .
$ git commit -m "lfsチェック"
$ git push
master 69456f9] lfsチェック
 2 files changed, 4 insertions(+)
 create mode 100644 .gitattributes
 create mode 100644 README.zip
$ git push
Git LFS: (0 of 1 files) 0 B / 182 B                                                                                                                                                                                             
batch request: exit status 1
error: failed to push some refs to 'git@host:taka/test.git'

あれ?何故かエラーorz

lfs.urlが必要!?

ググると、lfs.urlを設定しないといけない!?

$ git config --add lfs.url "http://host/taka/test.git/info/lfs"

$ git push
Username for 'http://host': <user>
Password for 'http://user@host':<password> 
Git LFS: (1 of 1 files) 182 B / 182 B                                                                                                                                                                                           
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 503 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To git@host:taka/test.git
   7c9ab00..69456f9  master -> master

今度は上手く行った。

sshで落としてみる

ローカルに再度取り直してみる

$ git clone git@host:taka/test.git
Cloning into 'test'...
remote: Counting objects: 73, done.
remote: Compressing objects: 100% (52/52), done.
remote: Total 73 (delta 20), reused 63 (delta 17)
Receiving objects: 100% (73/73), 6.79 KiB | 0 bytes/s, done.
Resolving deltas: 100% (20/20), done.
Checking connectivity... done.
Downloading README.zip (182 B)
Error downloading object: README.zip (7c29c490df3c8da5df78a6259fadb52402be02e38976b6c813e80cc346b00b2a)

Errors logged to /Users/taka/test/.git/lfs/objects/logs/20160903T092512.275224922.log
Use `git lfs logs last` to view the log.
error: external filter git-lfs smudge -- %f failed 2
error: external filter git-lfs smudge -- %f failed
fatal: README.zip: smudge filter lfs failed
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry the checkout with 'git checkout -f HEAD'

どうなっているか見てみる

ちょう面倒な事になっているwww

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	deleted:    .gitattributes
	deleted:    README.md
	deleted:    README.zip

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	.gitattributes
	README.md

リセット

reset して

$ git reset .
Unstaged changes after reset:
D	README.zip
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	deleted:    README.zip

元に戻そうと試みる

バイナリのファイルだけない状態になっているので元に戻そうと試みるが、cloneの時と同じエラー

$ git checkout .
Downloading README.zip (182 B)
Error downloading object: README.zip (7c29c490df3c8da5df78a6259fadb52402be02e38976b6c813e80cc346b00b2a)

Errors logged to /Users/taka/test/.git/lfs/objects/logs/20160903T092914.49014792.log
Use `git lfs logs last` to view the log.
error: external filter git-lfs smudge -- %f failed 2
error: external filter git-lfs smudge -- %f failed
fatal: README.zip: smudge filter lfs failed

また設定

$ git config --add lfs.url "http://host/taka/test.git/info/lfs"

$ git co .
Downloading README.zip (182 B)

戻った!!w
うーんσ(—’‘—;)

httpで落としてみる

$ git clone http://host/taka/test.git
Cloning into 'test'...
remote: Counting objects: 73, done.
remote: Compressing objects: 100% (52/52), done.
remote: Total 73 (delta 20), reused 63 (delta 17)
Unpacking objects: 100% (73/73), done.
Checking connectivity... done.
Downloading README.zip (182 B)

へっ!?すんなりcloneできたw
lfs.url は要らないの!?w

http もしくはssh+lfs.urlなのね。。。
これってlfshttpしか対応していないから?

そしたら

そしたら最初からhttpcloneすれば面倒な事はない!?

$ git clone http://host/taka/lfs-test.git
Cloning into 'lfs-test'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
$ cd lfs-test/
$ git lfs install
Updated pre-push hook.
Git LFS initialized.
$ git lfs track "*.zip"
Tracking *.zip
$ cp ../test/README.zip .
$ git add .
$ git commit -m "バイナリファイル"
[master (root-commit) df2dde7] バイナリファイル
 2 files changed, 4 insertions(+)
 create mode 100644 .gitattributes
 create mode 100644 README.zip
$ git push
Git LFS: (1 of 1 files) 182 B / 182 B                                                                                                                                                                                           
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 424 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To http://host/taka/lfs-test.git
 * [new branch]      master -> master

なんか微妙に扱いづらい部分がありますね。
ssh に対応してくれるか、自動でlfs.urlを追加してくれればいいのに・・・・・( ̄。 ̄ )ボソ...

参考サイト

6
12
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
6
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?