0
0

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 3 years have passed since last update.

Git LFSで特定コミット時点のファイルを別名で保存する

Posted at

git lfs checkout--toオプションが使えそうと思ったけどコンフリクトしていない状態だと使えなかった。
https://github.com/git-lfs/git-lfs/blob/master/docs/man/git-lfs-checkout.1.ronn

❌ダメな例:

$ git lfs checkout --base --to=tmp.png -- file.png
Could not checkout (are you not in the middle of a merge?): Git can't resolve ref: ":1:file.png"

LFSじゃない通常のファイルは git show <commit>:<file> でできる(参考: https://qiita.com/rbtnn/items/394178862e0a053dfb46 )けどLFSのファイルだとポインタの内容が表示されるだけ。

例:

$ git show HEAD:file.png
version https://git-lfs.github.com/spec/v1
oid sha256:hogehogehogehoge
size 1234

git lfs smudgeでポインタ情報から実体にしてくれるので、パイプしてやればいいだけだった。
https://github.com/git-lfs/git-lfs/blob/master/docs/man/git-lfs-smudge.1.ronn

git show HEAD:file.png | git lfs smudge > tmp.png

みたいな感じでお目当てのファイル実体を別名で保存することができた :tada:

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?