git and unity
TRANSCRIPT
Git and Unity
TIM PETTERSEN • SENIOR DEVELOPER • ATLASSIAN • @KANNONBOY
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
Why version control?
Why ?
Speed, speed, Speed
Everything is local
© Disney/Pixar
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?
shader-upgrade
stable master branch
isolated feature work
master
Branching workflow
Peer pressure
92%
8%
Bitbucket repositories, Git vs Hg
&
Unity Editor Settings
# 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
# Code IDE generated files *.sln .idea/ .consulo/ *.csproj *.unityproj *.suo …
Unity .gitignore Or use my Unity .gitignore @ bit.ly/unity-git
# Build artifacts *.exe *.apk *.log *.zip *.app …
Unity .gitignore Or use my Unity .gitignore @ bit.ly/unity-git
# OS special files Thumbs.db ehthumbs.db $RECYCLE.BIN/ *.lnk .DS_Store …
Unity .gitignore Or use my Unity .gitignore @ bit.ly/unity-git
Unity .gitignore Or use my Unity .gitignore @ bit.ly/unity-git
has a smallhad a large problem
data model
master
98ca9..
bab1e..
fad3d..cat .git/refs/heads/master$
fad3dd41d0cf3d1b6aa2d8ad0549ab2fcb1575d1
“Directed Acyclic Graph”
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$
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..
master
98ca9..
bab1e..
fad3d..
434bb..
98ca9..
bab1e..
fad3d..
master
98ca9..
bab1e..
fad3d..
master
50mb100mb150mb
98ca9..
bab1e..
fad3d..
master
Photo: Le Monde en Vidéo
Photo: Le Monde en Vidéo
Photo: Le Monde en Vidéo
Git LFS!
Git LOB!
Photo: Le Monde en Vidéo
!
Photo: Le Monde en Vidéo
Git LFS!
(Large File Storage)
Git LFS
dabad..
98ca9..
bab1e..
fad3d..
86753..
434bb..
$
LFS store
Git host
☞
☞
☞
Git host
LFS store
$
dabad..
98ca9..
bab1e..
fad3d..
86753..
434bb..
LFS store
git push$
☞
☞
☞
dabad..
98ca9..
bab1e..
fad3d..
86753..
434bb..
Git host
LFS store
git push$ ☞
☞
☞
dabad..
98ca9..
bab1e..
fad3d..
86753..
434bb..
Git host
git pull$
LFS store
Git host
☞
☞
☞
dabad..
98ca9..
bab1e..
fad3d..
86753..
434bb..
4749d..
bdd12..
778aa..
git pull$
LFS store
Git host
☞
☞
☞
dabad..
98ca9..
bab1e..
fad3d..
86753..
434bb..
4749d..
bdd12..
778aa..
git checkout bab1e$
LFS store
Git host
☞
☞
☞
dabad..
98ca9..
bab1e..
fad3d..
86753..
434bb..
4749d..
bdd12..
778aa..HEAD
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..
$ brew install git-lfs
$ git lfs install
$ git lfs track “*.png”
$ cat .gitattributes
*.png filter=lfs diff=lfs merge=lfs -text
SourceTree
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
# Git
$ git pull
$ git checkout
$ git add
$ git commit
$ git push
# Git LFS
$ git pull
$ git checkout
$ git add
$ git commit
$ git push
elephant.png
Work tree
dev
.git/lfs/objects
Clean filter(git-lfs clean)
☞
Index
elephant.png
$
.git/objects
git add
$
dev
.git/lfs/objects
Smudge filter(git-lfs smudge)
Work tree
elephant.png
☞
Commit tree
elephant.png.git/objects
LFS Store
git checkout
$ git push
Git LFS: (12 of 13 files, 1 skipped) 168.75 MB / 180.87 MB, 12.12 skipped
Counting objects: 22, done. ...
$ git pull
remote: Counting objects: 3, done. ... Downloading elephant.png (50.79 MB) ... 1 file changed, 2 insertions(+)
© Disney
Fetch the bare necessitiesFetch the bare necessities
© 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
Build automation
Multiple platforms
#2
GAME BUILDS?
Y’ALL GOT ANY MORE OF THEMY’ALL GOT ANY MORE OF THEM
GAME BUILDS?#3
master
Continuous integration
#4
#5
REDACTED
cloud build
What about the bucket?
go.atlassian.com/bitbucket-unity
Branching and merging
shader-upgrade
stable master branch
isolated feature work
master
Branching workflow
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
Merge conflictsgit rebase master
CONFLICT…
CONFLICT…
CONFLICT…
git stash pop
git pull
$
$
$
CONFLICT
Auto-merge failed
FIX THEN COMMIT
$ 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
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
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
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
Migrating to Git LFS
☞
Migrating to Git LFS
☞
98ca9..
bab1e..
fad3d.. ☞
100mb150mb150mb!?!?
$ git lfs track “*.obj”
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!
$ 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!
BFG Repo-Cleanerby @rtyley
BFG Repo-Cleaner
10-720x faster than filter-branch
built to kill history
Git LFS support
by @rtyley
$ 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!
$ brew install bfg
$ bfg —-convert-to-git-lfs “*.obj” --no-blob-protection
$ brew install bfg
$ bfg —-convert-to-git-lfs “*.obj” --no-blob-protection
$ bfg —-convert-to-git-lfs “*.png”--no-blob-protection
$ bfg —-convert-to-git-lfs “*.lfs.*”--no-blob-protection
Another approach…
Coming from SVN / P4?
go.atlassian.com/svn-to-git
go.atlassian.com/p4-to-git