相关文章推荐
冷静的小刀  ·  python ...·  2 月前    · 
腹黑的足球  ·  BETWEEN start_time ...·  4 月前    · 
  • Configure your GitLab server for Git LFS
  • Enable Git LFS for a project
  • Install the Git LFS client locally
  • Known limitations
  • How LFS objects affect repository size
  • Using Git LFS
  • File Locking
  • LFS objects in project archives
  • Related topics
  • Troubleshooting
  • Git Large File Storage (LFS)

    Managing large files such as audio, video and graphics files has always been one of the shortcomings of Git. The general recommendation is to not have Git repositories larger than 1 GB to preserve performance.

    Your Git LFS client communicates with the GitLab server over HTTPS. It uses HTTP Basic authentication to authorize client requests. After the request is authorized, Git LFS client receives instructions on where to fetch or where to push the large file.

    In the repository view, files tracked by Git LFS display an LFS badge next to the filename:

    Git LFS tracking status

    Configure your GitLab server for Git LFS

    To install Git LFS on your self-managed GitLab server, see GitLab Git Large File Storage (LFS) Administration .

    Enable Git LFS for a project

    Prerequisites:

    To do this:

    1. On the left sidebar, select Search or go to and find your project.
    2. Select Settings > General .
    3. Expand the Visibility, project features, permissions section.
    4. Turn on the Git Large File Storage (LFS) toggle.
    5. Select Save changes .

    Install the Git LFS client locally

    Install the Git LFS client appropriate for your operating system. GitLab requires version 1.0.1 or later of the Git LFS client.

    Known limitations
  • Git LFS v1 original API is not supported, because it was deprecated early in LFS development.
  • When SSH is set as a remote, Git LFS objects still go through HTTPS.
  • Any Git LFS request asks for HTTPS credentials, so we recommend a good Git credentials store.
  • Git LFS always assumes HTTPS so if you have GitLab server on HTTP you must add the URL to Git configuration manually .
  • Group wikis do not support Git LFS.
  • How LFS objects affect repository size

    When you add an LFS object to a repository, GitLab:

    1. Creates an LFS object.
    2. Associates the LFS object with the repository.
    3. Queues a job to recalculate your project’s statistics, including storage size and LFS object storage. Your LFS object storage is the sum of the size of all LFS objects associated with the repository.

    When your repository is forked, LFS objects from the upstream project are associated with the fork. When the fork is created, the LFS object storage for the fork is equal to the storage used by the upstream project. If new LFS objects are added to the fork, the total object storage changes for the fork, but not the upstream project.

    If you create a merge request from the fork back to the upstream project, any new LFS objects in the fork become associated with the upstream project.

    Using Git LFS

    Let’s take a look at the workflow for checking large files into your Git repository with Git LFS. For example, if you want to upload a very large file and check it into your Git repository:

    After you mark a file extension for tracking as a LFS object you can use Git as usual without redoing the command to track a file with the same extension:

    Make sure that .gitattributes is tracked by Git. Otherwise Git LFS doesn’t work properly for people cloning the project:

    Cloning the repository works the same as before. Git automatically detects the LFS-tracked files and clones them via HTTP. If you performed the git clone command with a SSH URL, you have to enter your GitLab credentials for HTTP authentication.

    If you already cloned the repository and you want to get the latest LFS object that are on the remote repository, such as for a branch from origin:

    Make sure your files aren’t listed in .gitignore , otherwise, they are ignored by Git and are not pushed to the remote repository.

    Migrate an existing repository to Git LFS

    Read the documentation on how to migrate an existing Git repository with Git LFS .

    Removing objects from LFS

    To remove objects from LFS:

    1. Use git filter-repo to remove the objects from the repository.
    2. Delete the relevant LFS lines for the objects you have removed from your .gitattributes file and commit those changes.

    File Locking

    See the documentation on File Locking .

    LFS objects in project archives

    Version history Introduced support for including Git LFS blobs inside project source downloads in GitLab 13.5 with a flag named include_lfs_blobs_in_archive . Disabled by default.
  • Enabled on GitLab.com and self-managed in GitLab 13.6.
  • Generally available in GitLab 14.0. Feature flag include_lfs_blobs_in_archive removed.
  • Prior to GitLab 13.5, project source downloads would include Git LFS pointers instead of the actual objects. For example, LFS pointers look like the following:

    version https://git-lfs.github.com/spec/v1
    oid sha256:3ea5dd307f195f449f0e08234183b82e92c3d5f4cff11c2a6bb014f9e0de12aa
    size 177735
    

    In GitLab version 13.5 and later, these pointers are converted to the uploaded LFS object.

    Technical details about how this works can be found in the development documentation for LFS .

    Troubleshooting

    Encountered n files that should have been pointers, but weren’t

    This error indicates the files are expected to be tracked by LFS, but the repository is not tracking them as LFS. This issue can be one potential reason for this error: Files not tracked with LFS when uploaded through the web interface

    To resolve the problem, migrate the affected file (or files) and push back to the repository:

      Migrate the file to LFS:

      git lfs migrate import --yes --no-rewrite "<your-file>"
      

      Push back to your repository:

      git push
      

      Optional. Clean up your .git folder:

      git reflog expire --expire-unreachable=now --all
      git gc --prune=now
      

    error: Repository or object not found

    This error can occur for a few reasons, including:

    Check if you have permissions to push to the project or fetch from the project.

    LFS object you are trying to push to the project or fetch from the project is not available to the project anymore. Probably the object was removed from the server.

    Invalid status for <url> : 501

    Git LFS logs the failures into a log file. To view this log file, while in project directory:

    If the status error 501 is shown, it is because:

    getsockopt: connection refused

    If you push an LFS object to a project and receive an error like this, the LFS client is trying to reach GitLab through HTTPS. However, your GitLab instance is being served on HTTP:

    This behavior is caused by Git LFS using HTTPS connections by default when a lfsurl is not set in the Git configuration.

    To prevent this from happening, set the LFS URL in project Git configuration:

    Credentials are always required when pushing an object note
    With 8.12 GitLab added LFS support to SSH. The Git LFS communication still goes over HTTP, but now the SSH client passes the correct credentials to the Git LFS client. No action is required by the user.

    Git LFS authenticates the user with HTTP Basic Authentication on every push for every object, so user HTTPS credentials are required.

    By default, Git has support for remembering the credentials for each repository you use. For more information, see the official Git documentation .

    For example, you can tell Git to remember the password for a period of time in which you expect to push the objects:

    git config --global credential.helper 'cache --timeout=3600'
    

    This remembers the credentials for an hour, after which Git operations require re-authentication.

    If you are using OS X you can use osxkeychain to store and encrypt your credentials. For Windows, you can use wincred or Microsoft’s Git Credential Manager for Windows .

    More details about various methods of storing the user credentials can be found on Git Credential Storage documentation .

    LFS objects are missing on push

    GitLab checks files to detect LFS pointers on push. If LFS pointers are detected, GitLab tries to verify that those files already exist in LFS on GitLab.

    Verify that LFS is installed locally and consider a manual push with git lfs push --all .

    If you are storing LFS files outside of GitLab you can disable LFS on the project by setting lfs_enabled: false with the projects API .

    Hosting LFS objects externally

    It is possible to host LFS objects externally by setting a custom LFS URL with git config -f .lfsconfig lfs.url https://example.com/<project>.git/info/lfs .

    You might choose to do this if you are using an appliance like a Nexus Repository to store LFS data. If you choose to use an external LFS store, GitLab can’t verify LFS objects. Pushes then fail if you have GitLab LFS support enabled.

    To stop push failure, LFS support can be disabled in the Project settings , which also disables GitLab LFS value-adds (Verifying LFS objects, UI integration for LFS).

    I/O timeout when pushing LFS objects

    You might get an error that states:

    When network conditions are unstable, the Git LFS client might time out when trying to upload files if network conditions are unstable.

    The workaround is to set the client activity timeout a higher value.

    For example, to set the timeout to 60 seconds:

    git config lfs.activitytimeout 60
    

    Docs

    Edit this page to fix an error or add an improvement in a merge request.
    Create an issue to suggest an improvement to this page.

    Product

    Create an issue if there's something you don't like about this feature.
    Propose functionality by submitting a feature request.
    Join First Look to help shape new features.

    Feature availability and product trials

    View pricing to see all GitLab tiers and features, or to upgrade.
    Try GitLab for free with access to all features for 30 days.

    Get Help

    If you didn't find what you were looking for, search the docs.
    If you want help with something specific and could use community support, post on the GitLab forum.
    For problems setting up or using this feature (depending on your GitLab subscription).

    Request support