Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Does github's gitignore remove package files when uploading on github?

Discussion in 'Package Manager' started by pagan_poetry, Aug 1, 2023.

  1. pagan_poetry

    pagan_poetry

    Joined:
    Feb 15, 2017
    Posts:
    101
    Github has it's own predefined .gitignore file for Unity so when I upload my project to Github it removes a lot of temporary files. Does it remove package files? Does Unity redownload and import them again when I open my cloned git project for the first time?

    I need to make sure that Unity would use exact the same original package versions when cloning project from Github. Because when your old project starts to use updated packages something can become broken.

    # This .gitignore file should be placed at the root of your Unity project directory
    #
    # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
    #
    /[Ll]ibrary/
    /[Tt]emp/
    /[Oo]bj/
    /[Bb]uild/
    /[Bb]uilds/
    /[Ll]ogs/
    /[Mm]emoryCaptures/

    # Asset meta data should only be ignored when the corresponding asset is also ignored
    !/[Aa]ssets/**/*.meta

    # Uncomment this line if you wish to ignore the asset store tools plugin
    # /[Aa]ssets/AssetStoreTools*

    # Autogenerated Jetbrains Rider plugin
    [Aa]ssets/Plugins/Editor/JetBrains*

    # Visual Studio cache directory
    .vs/

    # Gradle cache directory
    .gradle/

    # Autogenerated VS/MD/Consulo solution and project files
    ExportedObj/
    .consulo/
    *.csproj
    *.unityproj
    *.sln
    *.suo
    *.tmp
    *.user
    *.userprefs
    *.pidb
    *.booproj
    *.svd
    *.pdb
    *.mdb
    *.opendb
    *.VC.db

    # Unity3D generated meta files
    *.pidb.meta
    *.pdb.meta
    *.mdb.meta

    # Unity3D generated file on crash reports
    sysinfo.txt

    # Builds
    *.apk
    *.unitypackage

    # Crashlytics generated file
    crashlytics-build.properties
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    Package references are stored under ./Packages/manifest.json

    The package files themselves should be ignored, I suppose they are stored within Library or elsewhere on the user‘s system (AppData).

    The github default .gitignore works just fine. If anything you need to add more ignores such as temp output created by the WebGL Publisher asset, Unity Recorder‘s recordings and of course builds - provided you use the default locations which stores these files under the project‘s root folder.
     
    pagan_poetry likes this.
  3. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,051
    Packages/manifest.json
    defines which package versions your project uses directly, then
    Packages/packages-lock.json
    stores the versions of all direct and indirect dependencies. When you open a fresh checkout of a project on a different computer, Unity will redownload all packages based on the versions in the lock file. The lock file is intended to freeze the dependencies and to make a specific project state reproducible.

    You cannot check packages into version control, they're cached globally on your system and locally in
    Library/PackageCache
    but Unity doesn't support sharing the Library folder using version control. You could embed all dependencies but that seems like overkill.

    You should mainly watch out for Unity automatically upgrading packages. This should usually happen only when you update your project to a new Unity version, though, and you should be able to revert the changes to
    manifest.json
    and
    package-lock.json
    to revert to the previous versions (though they might not work with the new Unity version).
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    Thanks for the details! Didn't know the purpose of the lock file until now.

    Not just usually. This only ever happens when you upgrade the project to a newer Unity version, and then it will only upgrade Unity packages that are otherwise unsupported on that version. So reverting those Unity packages to their previous version is something you'd do "at your own risk" (issues? who knows which, when, where ...) and it may simply not be possible due to compile errors.