I have a pretty good solution. I’ll explain what I did. However, first I’ll explain the exact issue I was dealing with, to make sure it’s consistent with the rest of this thread. I believe this fully addresses the issue that @TomasRiker was referring to, in a relatively straightforward way.
First, the assumption is that it’s unreasonable to commit LightingData.asset to git. Either 1) Because the files are too large for the 100 MB limit on normal git files, or 2) Because, even if you decide to use LFS for storing these files, LightingData.asset files are enormous, they change very often, and you’ll spend all your time waiting for massive files to upload.
So, keeping LightingData.asset files out of git is essential. This is easily accomplished by adding LightingData.asset and LightingData.asset.meta to your .gitignore. That’s what I recommend if this is a decidedly solo project, and you won’t be building it on any other workstations. However, this approach falls apart either when a second developer joins the team, or you try to run the project on a different workstation. (In my case, I started really having to worry about this when I would occasionally create a Mac build on my MacBook.) As soon as two different workstations start getting involved, they’ll both create their own, independent LightingData.asset files of one doesn’t already exist in the project. These won’t get checked into git, due to .gitignore. But, the really big hassle is that Unity’s scenes need to explicitly reference a LightingData.asset file, by asset GUID. Every time you build lighting, the Scene will be updated to reference the local LightingData.asset’s GUID. This means that if Person A builds lighting, then commits changes to the scene, that scene will no longer reference the correct LightingData.asset on anyone else’s machine, resulting in no lighting being applied until those people rebuild lighting (which created yet another change to the scene, etc…)
So, to summarize:
- Putting LightingData.asset files into git causes storage and bandwidth headaches. It’s not feasible.
- However, not putting LightingData.asset into git causes us efficiency issues, as everyone needs to rebuild lighting any time anyone else rebuilds lighting.
Fortunately, there’s a middle-ground that pretty much solves this.
My solution to this problem is to commit a tiny “placeholder” LightingData.asset file to the project for each scene, which the scene references. The total size of the LightingData.asset is only about 37K, so there’s no storage concern. The scene file will reference this placeholder asset, so the GUID for LightingData.asset will remain stable even as lighting it built on various systems. Note that rebuilding lighting for a scene will modify the contents of LightingData.asset, but it will not change the GUID for that file.
In order to get this to work, however, it’s a little cumbersome.
My first thought was that I could temporarily remove LightingData.asset from .gitignore, commit the placeholder, then start ignoring LightingData.asset again. I figured that .gitignore would ignore any changes to files, even if they’re already part of the repo. That turned out to be incorrect. .gitignore is the gatekeeper from files being included in the repo. But if you’ve already included a file, .gitignore won’t cause the repo to ignore changes to that file moving forward.
The solution that I found worked properly was to use git update-index --skip-worktree
on specific files to cause git to really ignore those files after committing a placeholder. If you use --skip-worktree on a file, it more or less makes it invisible to git. Even if the file is already part of the repo, changes to that file won’t be tracked in git. So, the modified file won’t show up in your pending changes, even if you modify its contents. The key to all of this is that it’s the .meta file that determines a file’s GUID, not the file itself. So, you can replace a file with a file of the same name, and Unity will continue to think of it as having the same GUID as before.
So now we have all the pieces we need. Here’s how they fit together.
First, a bit of one-time setup: You need to create a placeholder LightingData.asset file. I accomplished this by creating a brand-new scene named “MostlyEmptyScene”, and baking lighting for that scene. The produced a tiny LightingData.asset of about 37K in size. I committed that LightingData.asset to git (temporarily un-ignoring LightingData.asset in .gitignore), just to have a definitive LightingData placeholder as part of the project. Commit this file is optional, but you’ll be duplicating this asset for each scene you want to configure from now on to use this placeholder approach, so it’s convenient to have easy access to it.
With the setup complete, it’s finally time to process a scene. Here are the correct steps, in the order I perform them.
-
Starting assumptions:
-
The .gitignore file is currently ignoring LightingData.asset and LightingData.asset.meta
-
You’ve created a placeholder LightingData.asset somewhere in your project (described above as “MostlyEmptyScene”)
-
Warning:
-
If you’re not comfortable with git and a bit of command line stuff, watch out here. Doing the following things wrong could potentially hose your project, and make it annoying to recover. So, only do this if you’re pretty sure you know what you’re doing. If you break something, I doubt I can help you fix it. 
-
Steps:
-
Build lighting for the scene you’re working with. Let’s call the scene “SceneX”. This will generate a LightingData.asset and a LightingData.asset.meta file in the project. However, due to the .gitignore, those files won’t be showing up as new files in git.
-
Edit your .gitignore file, and comment out the ignore for LightingData.asset and LightingData.asset.meta. You should now observe that these files are showing up as new files in git.
-
Do not commit those files yet. The LightingData.asset is potentially very large right now, and you don’t want to commit it like that.
-
On your filesystem, outside of Unity, copy the placeholder LightingData.asset from “MostlyEmptyScene” into SceneX’s lighting folder, replacing the actual LightingData.asset file. This will temporarily break lighting in your scene, but that’s fine.
-
Now commit the two files to git, LightingData.asset and LightingData.asset.meta, for SceneX.
-
Edit your .gitignore again, and resume ignoring LightingData.asset and LightingData.asset.meta.
-
Rebuild lighting for SceneX. Even though you’re currently ignoring LightingData.asset files, notice that rebuilding this will cause git to track the change you’ve just made to the file. We don’t want that.
-
On a git command line, execute this command: git update-index --skip-worktree /Path/To/SceneX/LightingData.asset
, where the path you specify is the path to SceneX’s LightingData.asset. Upon issuing that command, notice that git no longer tracks edits to that file.
-
You’re pretty much done. Now you can modify that LightingData.asset all you want, and its GUID won’t change. As long as you don’t delete the file, it should be stable for everyone. When pulling down the repo, all scenes will start out with their 37KB placeholder LightingData.asset file, which is all the repo knows about. Building light from that point on will merely update those placeholders with actual lighting data.
-
Caveats:
-
Using skip-worktree is not a repo-wide command. It only affects your local repo. This means that everyone on the team will need to use skip-worktree on all of the LightingData.asset files, or you’ll end up with some people committing changes to the lighting data. To make this easier, I created some shell scripts to skip-worktree on all LightingData.asset files in the project. I also have another file to reverse that, and “unskip” worktree, to get all the lighting data back to normal again. I’ll attach those scripts below.
-
Along with the previous caveat, you need to use that skip-worktree script any time you re-clone a repo. Again, skip-worktree is a local thing.
-
This doesn’t prevent the need for every team member to rebuild lighting on their own workstations. They’ll still need to do that in order for lighting to work properly. It just means that if Person A rebuilds lighting, it doesn’t break Person B’s lighting anymore, and doesn’t cause any git-related changes.
-
Notes:
-
You can clean up an existing project in a similar way. The best approach would probably be to more LightingData.meta and LightingData.asset.meta from .gitignore, so that these files are tracked again, then delete all the lighting data in your project. (You might want to leave a temporary file inside of the lighting data directory, to avoid committing empty directories to git, which can cause some issues.) Then, once you’ve cleared all the lighting data out of your project, you can pretty much start from the first step above.
Here are the two shell scripts I use when I need to skip or unskip worktree on the whole project. (The bit about line-endings is just there because these scripts keep getting messed up for me on one workstation, and I need to fix their line endings for them to work properly)
Important: These scripts use find ../..
to get to the project root, since in my project these scripts are two directories down in the project hierarchy. You’ll want to update find ../..
in your version of this so that it navigates to your Assets folder.
Skip worktree:
#/bin/sh
#
# This is used to prevent future edits to Lighting Data files from being picked
# up as git changes.
#
# If this file gets messed up by windows line endings, you can run this:
#
# awk '{ sub("\r$", ""); print }' skip_worktree_on_lighting_data.sh > temp_skip.sh
# mv temp_skip.sh skip_worktree_on_lighting_data.sh
# chmod 755 skip_worktree_on_lighting_data.sh
#
FILES=$(find ../.. -name "LightingData.asset")
for f in $FILES
do
echo "Performing Skip Worktree on $f"
git update-index --skip-worktree $f
done
Unskip worktree:
#/bin/sh
#
# This reverses the work done by skip-worktree on all LightingData.assets
#
# If this file gets messed up by windows line endings, you can run this:
#
# awk '{ sub("\r$", ""); print }' unskip_worktree_on_lighting_data.sh > temp_unskip.sh
# mv temp_unskip.sh unskip_worktree_on_lighting_data.sh
# chmod 755 unskip_worktree_on_lighting_data.sh
#
FILES=$(find ../.. -name "LightingData.asset")
for f in $FILES
do
echo "Performing No Skip Worktree on $f"
git update-index --no-skip-worktree $f
done