Debugging Merge Conflicts: .gitignore and folder structur

Forum for ARTS/COGS/CSCI 4540 Game Development II, Spring 2017

Debugging Merge Conflicts: .gitignore and folder structur

Postby BenChang » Mon Apr 17, 2017 8:55 pm

One thing we've all learned, usually the hard way, is the importance of the .gitignore file when doing projects in Unity, Unreal, or most other game engines. There are just tons of auto-generated files that you do not want in your commits, because they will break things.

With Unity, the Library directory is one example. This entire directory should not be in your repository, because it contains files that are autogenerated on everyone's computer. Overwriting them with Library files from another copy will clobber all kinds of things in your scene; not while not overwriting them will prevent you from committing other changes because Git thinks you have merge conflicts. It's essential that Library/ be untracked, that is, ignored completely by Git.

Symptoms of having your Library accidentally in your repository include:
  • You can't check out or pull any changes, because you get lots of errors like this:
    Code: Select all
    error: Your local changes to the following files would be overwritten by checkout: Library/metadata/1d/1d3b876f5ad72a5499d5bc9a099020a
  • Broken or vanished prefabs
  • Stuff disappears out of your scene
  • "Missing component" shows up in place of scripts on your prefabs, even though they were just there
  • Nothing works :evil: :evil: :evil: :evil: :evil: :evil:
  • If you browse the repo on the bitbucket or github website, you can see the Library folder in there

Why is the Library there?? You surely set up a .gitignore when you created the repository, so what the heck?

Take a look at the .gitignore and verify it really is there.

It commonly looks like this:

Code: Select all

# Autogenerated VS/MD solution and project files

/[LI]brary/ means to ignore Library. The trailing slash means only match directories named Library, not regular files. The square brackets match either capital L or lower-case l, so either Library or library.

The prefix slash is important too, and this is where problems can come from. The leading slash only matches patterns relative to the .gitignore file. So if your .gitignore is in the top level of your Unity project, it will match the Library/ directory, but not, say, Assets/Models/Environments/Town/Library/.

This is fine if your .gitignore is place in the top level of your Unity project.

You may have a directory structure like this, however:

  • OurGame/
    • README
    • .gitignore
    • ArtStuff/
      • Concept Art/
      • MayaFiles/
    • Writing
    • OurGame_UnityProject

      • Assets
      • Library

since .gitignore is above the level where the Unity project is, the Library directory won't be matched. It'd have to be [code]/OurGame_UnityProject/[Ll]ibrary/[code] to match it.

An easy solution is to put the .gitignore into the Unity project directory. You can have it in both places. A .gitignore in any subdirectory will add on to and override anything set in parent directories.

For more about the .gitignore syntax, the shell globbing and regex syntax it uses, etc:
User avatar
Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm

Return to Game Development II Spring 2017

Who is online

Users browsing this forum: No registered users and 1 guest