git and unity

86
Git and Unity TIM PETTERSEN SENIOR DEVELOPER ATLASSIAN @KANNONBOY

Upload: tim-pettersen

Post on 21-Mar-2017

152 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Git and Unity

Git and Unity

TIM PETTERSEN • SENIOR DEVELOPER • ATLASSIAN • @KANNONBOY

Page 2: Git and Unity

G I T A N D U N I T Y

W H Y G I T ?

G A M E A S S E T S

B R A N C H I N G A N D M E R G I N G

Git and Unity

B U I L D A U TO M AT I O N

I N T E R M E Z Z O

Page 3: Git and Unity

Why version control?

Page 4: Git and Unity

Why ?

Page 5: Git and Unity

Speed, speed, Speed

Page 6: Git and Unity

Everything is local

Page 7: Git and Unity

© Disney/Pixar

Page 8: Git and Unity

Chapter Title Here

Spilled beer on hard drive?Malicious vandalism?

Data center hit by meteor?

Accidental branch deletion?

No biggie! We’re

on

rm -rf in the wrong directory?

Page 9: Git and Unity

shader-upgrade

stable master branch

isolated feature work

master

Branching workflow

Page 10: Git and Unity

Peer pressure

92%

8%

Bitbucket repositories, Git vs Hg

Page 11: Git and Unity

&

Page 12: Git and Unity

Unity Editor Settings

Page 13: Git and Unity

# Unity generated files /[Ll]ibrary/ /[Tt]emp/ /[Oo]bj/ /[Bb]uild/ /[Bb]uilds/ /Assets/AssetStoreTools*

Unity .gitignore Or use my Unity .gitignore @ bit.ly/unity-git

Page 14: Git and Unity

# Code IDE generated files *.sln .idea/ .consulo/ *.csproj *.unityproj *.suo …

Unity .gitignore Or use my Unity .gitignore @ bit.ly/unity-git

Page 15: Git and Unity

# Build artifacts *.exe *.apk *.log *.zip *.app …

Unity .gitignore Or use my Unity .gitignore @ bit.ly/unity-git

Page 16: Git and Unity

# OS special files Thumbs.db ehthumbs.db $RECYCLE.BIN/ *.lnk .DS_Store …

Unity .gitignore Or use my Unity .gitignore @ bit.ly/unity-git

Page 17: Git and Unity

Unity .gitignore Or use my Unity .gitignore @ bit.ly/unity-git

Page 18: Git and Unity

has a smallhad a large problem

Page 19: Git and Unity

data model

Page 20: Git and Unity

master

98ca9..

bab1e..

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

fad3dd41d0cf3d1b6aa2d8ad0549ab2fcb1575d1

“Directed Acyclic Graph”

Page 21: Git and Unity

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$

Page 22: Git and Unity

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

Page 23: Git and Unity

master

98ca9..

bab1e..

fad3d..

434bb..

Page 24: Git and Unity

98ca9..

bab1e..

fad3d..

master

Page 25: Git and Unity

98ca9..

bab1e..

fad3d..

master

Page 26: Git and Unity

50mb100mb150mb

98ca9..

bab1e..

fad3d..

master

Page 27: Git and Unity

Photo: Le Monde en Vidéo

Page 28: Git and Unity

Photo: Le Monde en Vidéo

Page 29: Git and Unity

Photo: Le Monde en Vidéo

Page 30: Git and Unity

Git LFS!

Git LOB!

Photo: Le Monde en Vidéo

Page 31: Git and Unity

!

Photo: Le Monde en Vidéo

Git LFS!

Page 32: Git and Unity

(Large File Storage)

Git LFS

Page 33: Git and Unity

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

$

LFS store

Git host

Page 34: Git and Unity

Git host

LFS store

$

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

Page 35: Git and Unity

LFS store

git push$

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

Git host

Page 36: Git and Unity

LFS store

git push$ ☞

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

Git host

Page 37: Git and Unity

git pull$

LFS store

Git host

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

4749d..

bdd12..

778aa..

Page 38: Git and Unity

git pull$

LFS store

Git host

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

4749d..

bdd12..

778aa..

Page 39: Git and Unity

git checkout bab1e$

LFS store

Git host

dabad..

98ca9..

bab1e..

fad3d..

86753..

434bb..

4749d..

bdd12..

778aa..HEAD

Page 40: Git and Unity

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 41: Git and Unity

$ brew install git-lfs

$ git lfs install

Page 42: Git and Unity

$ git lfs track “*.png”

$ cat .gitattributes

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

Page 43: Git and Unity

SourceTree

Page 44: Git and Unity

What to track?Yep Probably Nah

SFXMusic

TexturesSpritesheets

FMV

Code

FontsMaterials

Text

MeshesAnimations

Scenes

if they’re big or change frequently

big stuff Or use my Unity .gitattributes @ bit.ly/unity-git

Page 45: Git and Unity

# Git

$ git pull

$ git checkout

$ git add

$ git commit

$ git push

# Git LFS

$ git pull

$ git checkout

$ git add

$ git commit

$ git push

Page 46: Git and Unity

elephant.png

Work tree

dev

.git/lfs/objects

Clean filter(git-lfs clean)

Index

elephant.png

$

.git/objects

git add

Page 47: Git and Unity

$

dev

.git/lfs/objects

Smudge filter(git-lfs smudge)

Work tree

elephant.png

Commit tree

elephant.png.git/objects

LFS Store

git checkout

Page 48: Git and Unity

$ git push

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

Counting objects: 22, done. ...

Page 49: Git and Unity

$ git pull

remote: Counting objects: 3, done. ... Downloading elephant.png (50.79 MB) ... 1 file changed, 2 insertions(+)

Page 50: Git and Unity

© Disney

Fetch the bare necessitiesFetch the bare necessities

Page 51: Git and Unity

© Disney

# don’t pull down cutscene videos $ git lfs fetch --exclude ‘Assets/Video/**’

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

$ git config lfs.fetchexclude ‘Assets/Video/**’

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

Fetch the bare necessitiesFetch the bare necessities

Page 52: Git and Unity

Build automation

Page 53: Git and Unity

Comic: Randall Munroe http://xkcd.com/303/

#1

Page 54: Git and Unity

Multiple platforms

#2

Page 55: Git and Unity

GAME BUILDS?

Y’ALL GOT ANY MORE OF THEMY’ALL GOT ANY MORE OF THEM

GAME BUILDS?#3

Page 56: Git and Unity

master

Continuous integration

#4

Page 57: Git and Unity

#5

REDACTED

Page 58: Git and Unity

cloud build

Page 59: Git and Unity
Page 60: Git and Unity
Page 61: Git and Unity
Page 62: Git and Unity
Page 63: Git and Unity

What about the bucket?

Page 64: Git and Unity
Page 65: Git and Unity

go.atlassian.com/bitbucket-unity

Page 66: Git and Unity

Branching and merging

Page 67: Git and Unity

shader-upgrade

stable master branch

isolated feature work

master

Branching workflow

Page 68: Git and Unity

CONFLICT (content): Merge conflict in Assets/Scenes/GameOver.unity

Automatic merge failed; fix conflicts and then commit the result.

Merge conflicts$Auto-merging Assets/Scenes/GameOver.unitygit merge feature/endgame-spiceup

Page 69: Git and Unity

Merge conflictsgit rebase master

CONFLICT…

CONFLICT…

CONFLICT…

git stash pop

git pull

$

$

$

Page 70: Git and Unity

CONFLICT

Auto-merge failed

FIX THEN COMMIT

Page 71: Git and Unity

$ git merge feature/endgame-spiceup Auto-merging Assets/Scenes/GameOver.unity

CONFLICT (content): Merge conflict in Assets/Scenes/GameOver.unity

Automatic merge failed; fix conflicts and then commit the result.

Unity SmartMerge SmartMerge guide @ bit.ly/unity-git

Page 72: Git and Unity

Unity SmartMerge SmartMerge guide @ bit.ly/unity-git

$ git mergetoolMerging: Assets/Scenes/GameOver.unity …

Assets/Scenes/GameOver.unity seems unchanged. Was the merge successful [y/n]?

ignore this

y

Page 73: Git and Unity

Unity SmartMerge[mergetool “unity_yaml”] cmd = UnityYAMLMerge merge -p \ $BASE $REMOTE $LOCAL $MERGED trustExitCode = false keepTemporaries = true keepBackup = false

[merge] tool = unity_yaml

SmartMerge guide @ bit.ly/unity-git

Page 74: Git and Unity

bit.ly/unity-gitUnity + Git config

go.atlassian.com/bitbucket-unityBitbucket ❤ Unity

go.atlassian.com/git-lfsGit LFS

bitbucket.orgBitbucket Cloud

Lookingfor

more?

For occasional Git, JIRA& Bitbucket trivia

@kannonboy

Page 75: Git and Unity

Migrating to Git LFS

Page 76: Git and Unity

Migrating to Git LFS

Page 77: Git and Unity

98ca9..

bab1e..

fad3d.. ☞

100mb150mb150mb!?!?

$ git lfs track “*.obj”

Page 78: Git and Unity

git filter-branch

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

DON’T DO

THIS!

Page 79: Git and Unity

$ git filter—branch --prune-empty --tree-filter ' git config -f .gitconfig lfs.url “https://bitbucket.example.com/team/repo.git” git lfs track "*.obj" 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

DON’T DO

THIS

EITHER!

Page 80: Git and Unity

BFG Repo-Cleanerby @rtyley

Page 81: Git and Unity

BFG Repo-Cleaner

10-720x faster than filter-branch

built to kill history

Git LFS support

by @rtyley

Page 82: Git and Unity

$ git filter—branch --prune-empty --tree-filter ' git config -f .gitconfig lfs.url “https://bitbucket.example.com/team/repo.git” git lfs track "*.obj" 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

DON’T DO

THIS

EITHER!

Page 83: Git and Unity

$ brew install bfg

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

Page 84: Git and Unity

$ brew install bfg

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

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

Page 85: Git and Unity

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

Another approach…

Page 86: Git and Unity

Coming from SVN / P4?

go.atlassian.com/svn-to-git

go.atlassian.com/p4-to-git