104
TIM PETTERSEN SENIOR DEVELOPER ATLASSIAN @KANNONBOY Tracking game assets with Git LFS

Tracking large game assets with Git LFS

Embed Size (px)

Citation preview

Page 1: Tracking large game assets with Git LFS

TIM PETTERSEN • SENIOR DEVELOPER • ATLASSIAN • @KANNONBOY

Tracking game assets with Git LFS

Page 2: Tracking large game assets with Git LFS

@kannonboyPhoto: Le Monde en Vidéo

@kannonboy

Page 3: Tracking large game assets with Git LFS

@kannonboyPhoto: Le Monde en Vidéo

@kannonboy

Page 4: Tracking large game assets with Git LFS

@kannonboy@kannonboyPhoto: Le Monde en Vidéo

Page 5: Tracking large game assets with Git LFS

@kannonboy

Git LFS!

Git LOB!

@kannonboyPhoto: Le Monde en Vidéo

Page 6: Tracking large game assets with Git LFS

@kannonboy

!

@kannonboyPhoto: Le Monde en Vidéo

Git LFS!

Page 7: Tracking large game assets with Git LFS

TIM PETTERSEN • SENIOR DEVELOPER • ATLASSIAN • @KANNONBOY

Tracking game assets with Git LFS

Page 8: Tracking large game assets with Git LFS

@kannonboy

G I T L F S

T H E P R O B L E M W I T H B I G F I L E S

Agenda

C O N V E R T I N G Y O U R R E P O

T I P S F O R T E A M S

Page 9: Tracking large game assets with Git LFS

@kannonboy

data model

Page 10: Tracking large game assets with Git LFS

master

fad3d..cat .git/refs/heads/master$

fad3dd41d0cf3d1b6aa2d8ad0549ab2fcb1575d1

@kannonboy

Page 11: Tracking large game assets with Git LFS

master

98ca9..

bab1e..

fad3d..cat .git/refs/heads/master$

fad3dd41d0cf3d1b6aa2d8ad0549ab2fcb1575d1

@kannonboy“Directed Acyclic Graph”

Page 12: Tracking large game assets with Git LFS

master

98ca9..

bab1e..

fad3d..

434bb..tree

bab1e..parent

Tim P <kannonboy@…> 1455209277 -0800committer

Tim P <kannonboy@…> 1455209277 -0800author

My life is my commit message.

git cat-file -p 98ca9$

@kannonboy

Page 13: Tracking large game assets with Git LFS

git cat-file -p 434bb

ace23..100644 blob .gitignoredbdbd..100644 blob .gitattributesa0bc3..040000 tree Assets33d33..040000 tree ProjectSettingsb1de7..100755 blob build.sh7011e..100755 blob README.md

typefilemode SHA-1

master

98ca9..

bab1e..

fad3d..$

434bb..

@kannonboy

Page 14: Tracking large game assets with Git LFS

master

98ca9..

bab1e..

fad3d..

434bb..

@kannonboy

Page 15: Tracking large game assets with Git LFS

98ca9..

bab1e..

fad3d..

master

@kannonboy

Page 16: Tracking large game assets with Git LFS

98ca9..

bab1e..

fad3d..

master

@kannonboy

Page 17: Tracking large game assets with Git LFS

50mb

98ca9..

bab1e..

fad3d..

master

@kannonboy

Page 18: Tracking large game assets with Git LFS

50mb100mb98ca9..

bab1e..

fad3d..

master

@kannonboy

Page 19: Tracking large game assets with Git LFS

50mb100mb150mb

98ca9..

bab1e..

fad3d..

master

@kannonboy

Page 20: Tracking large game assets with Git LFS

@kannonboy

Page 21: Tracking large game assets with Git LFS

@kannonboy

Page 22: Tracking large game assets with Git LFS

@kannonboy

(Large File Storage)

Git LFS

Page 23: Tracking large game assets with Git LFS

@kannonboy

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

$

LFS store

Git host

Page 24: Tracking large game assets with Git LFS

@kannonboy

Git host

LFS store

$

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

Page 25: Tracking large game assets with Git LFS

@kannonboy

LFS store

git push$

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

Git host

Page 26: Tracking large game assets with Git LFS

@kannonboy

LFS store

git push$

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

Git host

Page 27: Tracking large game assets with Git LFS

@kannonboy

LFS store

git push$ ☞

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

Git host

Page 28: Tracking large game assets with Git LFS

@kannonboy

git pull$

LFS store

Git host

Page 29: Tracking large game assets with Git LFS

@kannonboy

git pull$

LFS store

Git host

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

4749d..

bdd12..

778aa..

Page 30: Tracking large game assets with Git LFS

@kannonboy

git pull$

LFS store

Git host

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

4749d..

bdd12..

778aa..

Page 31: Tracking large game assets with Git LFS

@kannonboy

git checkout bab1e$

LFS store

Git host

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

4749d..

bdd12..

778aa..HEAD

Page 32: Tracking large game assets with Git LFS

@kannonboy

git checkout bab1e$

LFS store

Git host

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

4749d..

bdd12..

778aa..HEAD

Page 33: Tracking large game assets with Git LFS

@kannonboy

https://git-lfs.github.com/spec/v1version

sha256:325ddfb…oid

29342295size

git cat-file -p 4749d$ ☞

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

4749d..

bdd12..

778aa..

Page 34: Tracking large game assets with Git LFS

@kannonboy

$ brew install git-lfs

$ git lfs install

Page 35: Tracking large game assets with Git LFS

@kannonboy

$ cat ~/.gitconfig

[filter "lfs"] clean = git-lfs clean %f smudge = git-lfs smudge %f required = true

Page 36: Tracking large game assets with Git LFS

@kannonboy

$ git lfs track “*.mp4”

$ cat .gitattributes

*.mp4 filter=lfs diff=lfs merge=lfs -text

Page 37: Tracking large game assets with Git LFS

@kannonboy

massive_video.mp4

Work tree

dev

.git/lfs/objects

Clean filter(git-lfs clean)

Index

massive_video.mp4

$

.git/objects

git add

Page 38: Tracking large game assets with Git LFS

@kannonboy

$

dev

.git/lfs/objects

Smudge filter(git-lfs smudge)

Work tree

massive_video.mp4

Commit tree

massive_video.mp4.git/objects

LFS Store

git checkout

Page 39: Tracking large game assets with Git LFS

@kannonboy

.git/lfs/objects

.git/objectsHosted repo

LFS store

git push / pull

Page 40: Tracking large game assets with Git LFS

@kannonboy

$ ls .git/hooks/

commit-msg.sample post-update.sample pre-commit.sample pre-push ...

Page 41: Tracking large game assets with Git LFS

@kannonboy

$ git push

Git LFS: (12 of 13 files, 1 skipped) 168.75 MB / 180.87 MB, 12.12 skipped

Counting objects: 22, done. ...

Page 42: Tracking large game assets with Git LFS

@kannonboy

$ git pull

remote: Counting objects: 3, done. ... Downloading massive_video.mp4 (38.79 MB) ... 1 file changed, 2 insertions(+)

Page 43: Tracking large game assets with Git LFS

@kannonboy

$ git clone ssh://git@bitbucke..

Cloning into ‘big_repo’ ... Downloading massive_video.mp4 (38.79 MB) ... Checking out files: 100% (13/13), done.

Page 44: Tracking large game assets with Git LFS

@kannonboy

POST .../repo.git

I need object cafebabe

@kannonboy

/info/lfs/objects/batch{“objects”:[

{“oid”: “cafebabe...”,“size”: 40689401}, ...

],“operation”: “download”}

Page 45: Tracking large game assets with Git LFS

@kannonboy

200 OK

{“objects”:[ {“oid”: “cafebabe…”, “size”: 40689401, “actions”: {

“download”: { “href”: “https://…/lfs/cafebabe…”,

@kannonboy

cafebabe is over there

} }

...

Page 46: Tracking large game assets with Git LFS

@kannonboy

200 OK

{“objects”:[ {“oid”: “cafebabe…”, “size”: 40689401, “actions”: {

“download”: { “href”: “https://…/lfs/cafebabe…”,

@kannonboy

cafebabe is over there

“header”: {“Authorization”: “JWT eyJ0eXA…”,

} } }

...

Page 47: Tracking large game assets with Git LFS

@kannonboy

$ ssh git@bitbucket git-lfs-authenticate \ project/repo.git download

where is the LFS API?

@kannonboy

Page 48: Tracking large game assets with Git LFS

@kannonboy

$ ssh git@bitbucket git-lfs-authenticate \ project/repo.git download

{“href”: “https://…/lfs/objects/batch”,“header”: {“Authorization”: “JWT eyJ0eXA...”

}}

where is the LFS API?

the LFS API is over there

@kannonboy

Page 49: Tracking large game assets with Git LFS

@kannonboy

$ ssh git@bitbucket git-lfs-authenticate \ project/repo.git download

{“href”: “https://…/lfs/objects/batch”,“header”: {“Authorization”: “JWT eyJ0eXA...”

}}

where is the LFS API?

the LFS API is over there

@kannonboy

Page 50: Tracking large game assets with Git LFS

@kannonboy

LFS aware Git server LFS storeDev

git clone https://..

repo data

POST /info/lfs/objects/batch

LFS objects hypermedia

GET …/<objectSHA>

smudge filter

happens once per

file checked out

Page 51: Tracking large game assets with Git LFS

@kannonboy

LFS storeDev

git lfs clone https://..

repo data

GET …/<objectSHA>

batched

smudge filter

subtle difference!

POST /info/lfs/objects/batch

LFS objects hypermedia

LFS aware Git server

Page 52: Tracking large game assets with Git LFS

@kannonboy

# git pull with LFS disabled $ git -c filter.lfs.smudge= \ -c filter.lfs.required=false pull

# fetch LFS objects as batch $ git lfs pull

Speeding up pulls

Page 53: Tracking large game assets with Git LFS

@kannonboy

# define a git alias $ git config --global alias.plfs "\!git \ -c filter.lfs.smudge= \ -c filter.lfs.required=false pull \ && git lfs pull"

# then simply... $ git plfs

Speeding up pulls

Page 54: Tracking large game assets with Git LFS

@kannonboy

Converting to Git LFS

Page 55: Tracking large game assets with Git LFS

@kannonboy

Converting to Git LFS

Page 56: Tracking large game assets with Git LFS

98ca9..

bab1e..

fad3d..

100mb150mb

$ git lfs track “*.mp4”

Page 57: Tracking large game assets with Git LFS

98ca9..

bab1e..

fad3d.. ☞

100mb150mb150mb!?!?

$ git lfs track “*.mp4”

Page 58: Tracking large game assets with Git LFS

@kannonboy

git filter-branch

$ git filter-branch --force --index-filter \ 'git rm --cached --ignore-unmatch big_video.mp4’ \ --prune-empty --tag-name-filter cat -- --all

DON’T DO

THIS!

Page 59: Tracking large game assets with Git LFS

@kannonboy

$ git filter—branch --prune-empty --tree-filter ' git config -f .gitconfig lfs.url “https://bitbucket.example.com/team/repo.git” git lfs track "*.mp4" git add .gitattributes .gitconfig

for file in $(git ls-files | xargs git check-attr filter | grep "filter: lfs" | sed -r "s/(.*): filter: lfs/\1/"); do git rm -f --cached ${file} git add ${file} done' --tag-name-filter cat -- --all

@kannonboy

DON’T DO

THIS

EITHER!

Page 60: Tracking large game assets with Git LFS

@kannonboy

BFG Repo-Cleaner

@kannonboy

by @rtyley

Page 61: Tracking large game assets with Git LFS

@kannonboy

BFG Repo-Cleaner

@kannonboy

10-720x faster than filter-branch

built to kill history

Git LFS support

by @rtyley

Page 62: Tracking large game assets with Git LFS

@kannonboy

$ git filter—branch --prune-empty --tree-filter ' git config -f .gitconfig lfs.url “https://bitbucket.example.com/team/repo.git” git lfs track "*.mp4" git add .gitattributes .gitconfig

for file in $(git ls-files | xargs git check-attr filter | grep "filter: lfs" | sed -r "s/(.*): filter: lfs/\1/"); do git rm -f --cached ${file} git add ${file} done' --tag-name-filter cat -- --all

@kannonboy

DON’T DO

THIS

EITHER!

Page 63: Tracking large game assets with Git LFS

@kannonboy

$ brew install bfg

$ bfg —-convert-to-git-lfs “*.mp4” --no-blob-protection

Page 64: Tracking large game assets with Git LFS

@kannonboy

What to track?Yes Maybe No

SFXMusic

TexturesSpritesheets

FMV

Code

FontsMaterials

Text

MeshesAnimations

Scenes

if they’re big or change frequently

big stuff

Page 65: Tracking large game assets with Git LFS

@kannonboy

$

317352 angrybots194424 angrybots/Assets112884 angrybots/Assets/Textures32220 angrybots/Assets/Sounds24460 angrybots/Assets/Objects…

du -k angrybots | sort -nr

What to track?

Page 66: Tracking large game assets with Git LFS

@kannonboy

Repofactoring

@kannonboy

Page 67: Tracking large game assets with Git LFS

@kannonboy

Identifying large objects

github.com/bloomberg/repofactor

by @hashpling

Page 68: Tracking large game assets with Git LFS

@kannonboy

$

a295ef4… 102437 953722cc7063… 152171 140443

blob SHA size on disk average blob size

generate-larger-than 50000

Identifying large objects

Page 69: Tracking large game assets with Git LFS

@kannonboy

, PNG, 512 x 512, WAVE audio, 16 bit

a295ef4… 102437 95372 2cc7063… 152171 140443

$ generate-larger-than 50000 \| add-file-info

Identifying large objects

Page 70: Tracking large game assets with Git LFS

@kannonboy

…/ReBirth.png a295ef4… 102437 95372, PNG… …/bot_die.wav 2cc7063… 152171 140443, WAVE…

$ generate-larger-than 50000 \ | add-file-info

$ report-on-large-objects big-stuff.txt

paths

> big-stuff.txt

Identifying large objects

Page 71: Tracking large game assets with Git LFS

@kannonboy

…/bot_die.wav 2cc7063… 152171 140443, WAVE… …/ReBirth.png a295ef4… 102437 95372, PNG…

$ generate-larger-than 50000 \ | add-file-info

$ report-on-large-objects big-stuff.txt

> big-stuff.txt

Identifying large objects

\| sort -k3nr

order by average blob size

Page 72: Tracking large game assets with Git LFS

@kannonboy

$ bfg —-convert-to-git-lfs “*.wav” --no-blob-protection

Identifying large objects

$ bfg —-convert-to-git-lfs “*.png”--no-blob-protection

run once per pattern

Page 73: Tracking large game assets with Git LFS

@kannonboy

Enable in Bitbucket

Page 74: Tracking large game assets with Git LFS

@kannonboy

Page 75: Tracking large game assets with Git LFS

@kannonboy

Page 76: Tracking large game assets with Git LFS

@kannonboy

Tips for teams

Page 77: Tracking large game assets with Git LFS

@kannonboyBeware merge conflicts @kannonboy

Page 78: Tracking large game assets with Git LFS

@kannonboy

…meanwhile in

Page 79: Tracking large game assets with Git LFS

@kannonboy

Locking

@kannonboy

Source: etonline.com/music

Page 80: Tracking large game assets with Git LFS

@kannonboy

master

feature0

feature1

File locking (single branch model)

LAME

Page 81: Tracking large game assets with Git LFS

@kannonboy

master

feature0

feature1

File locking (multi branch model)

Page 82: Tracking large game assets with Git LFS

@kannonboy

master

feature0

feature1

File locking (multi branch model)

Page 83: Tracking large game assets with Git LFS

@kannonboy

master

feature0

feature1

File locking (multi branch model)

Page 84: Tracking large game assets with Git LFS

@kannonboy

master

feature0

feature1

File locking (multi branch model)

Page 85: Tracking large game assets with Git LFS

@kannonboy

$ git lfs lock <path>

$ git lfs unlock <path>

$ git lfs locks [-i id] [-p path]

Page 86: Tracking large game assets with Git LFS

@kannonboy

Until then…

Page 87: Tracking large game assets with Git LFS

@kannonboyTeamwork @kannonboyTeamwork

Page 88: Tracking large game assets with Git LFS

@kannonboy

$ git lfs fetch

master

feature0

feature1

Page 89: Tracking large game assets with Git LFS

@kannonboy

$ git lfs fetch

master

feature0

feature1

--recent

Page 90: Tracking large game assets with Git LFS

@kannonboy

$ git lfs fetch

master

feature0

feature1

--recent

T-minus 7 days

Page 91: Tracking large game assets with Git LFS

@kannonboy

$ git config lfs.fetchrecentalways “true”

lfs.fetchrecentrefsdays

lfs.fetchrecentremoterefs

lfs.fetchrecentcommitsdays

(default = 7)

(default = 0)

$ git lfs fetch --recent

(default = true)

Page 92: Tracking large game assets with Git LFS

@kannonboy

$

master

feature0

feature1

git lfs prune

Page 93: Tracking large game assets with Git LFS

@kannonboy

$

master

feature0

feature1

--recent(7 days)

prune(10 days)

git lfs prune

Page 94: Tracking large game assets with Git LFS

@kannonboy

lfs.pruneoffsetdays

lfs.pruneverifyremotealways

(default = 3)

Set this!

$ git lfs prune

Page 95: Tracking large game assets with Git LFS

@kannonboy

Server-side deletion

Page 96: Tracking large game assets with Git LFS

@kannonboyFetch the bare necessitiesFetch the bare necessities @kannonboy© Disney

Page 97: Tracking large game assets with Git LFS

@kannonboy

# for a build that just runs the unit tests $ git lfs fetch --exclude Assets/Textures/**

# for an audio engineer $ git lfs fetch --include Assets/Sounds/**

$ git config lfs.fetchexclude Assets/Textures/**

$ git config lfs.fetchinclude Assets/Sounds/**

Page 98: Tracking large game assets with Git LFS

@kannonboyIDEs & GUI tools @kannonboy

Page 99: Tracking large game assets with Git LFS

@kannonboy

Page 100: Tracking large game assets with Git LFS

@kannonboy

Page 101: Tracking large game assets with Git LFS

@kannonboy

SourceTree

Page 102: Tracking large game assets with Git LFS

@kannonboy

version 4.3+Bitbucket Server

go.atlassian.com/git-lfsdocs

github.com/github/git-lfssource

available now!bitbucket.org

Lookingfor

more?

For occasional Git, JIRA& Bitbucket trivia

Page 103: Tracking large game assets with Git LFS

@kannonboy

unlimited private and public repositories for teams of up to 5 Git LFS storage tier builds and deployments tier with Bitbucket Pipelines pull requests, branch controls, JIRA integration, etc

go.atlassian.com/gaming

FREE

Page 104: Tracking large game assets with Git LFS

@kannonboy

Tweet your game or app with the hashtag

#BuiltwithBitbucket

for a chance to be featured on the Bitbucket gaming

page