Skip to content

Commit

Permalink
updating LFS posts
Browse files Browse the repository at this point in the history
  • Loading branch information
joshjohanning committed Aug 13, 2024
1 parent 7e52fde commit eb330dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
17 changes: 17 additions & 0 deletions _posts/2023-09-07-migrate-git-lfs-artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ The repository has been migrated, including the LFS artifacts:
![Git LFS file](git-lfs-dark.png){: .shadow }{: .dark }
_File stored in Git LFS file in GitHub_

## Alternative Method

The method above worked well for me in my tests, even in tests with 1,000 LFS artifacts each 1mb in size. However, I have seen issues running these commands for some customers with larger repositories. Sometimes the `git lfs fetch` or `git lfs push` will hang or not appear to migrate all of the LFS artifacts. If you run into issues, you can run this script to more thoroughly (but slower) way to migrate the LFS artifacts. It works by looping through each LFS object and pushing it individually pushing it.

The alternative script to migrate the LFS artifacts to another repository:

```bash
git clone --mirror <source-url> temp
cd temp
for object_id in $(git lfs ls-files --all --long | awk '{print $1}'); do
git lfs push --object-id remote "$object_id"
done
```

> Source for the [script](https://github.com/git-lfs/git-lfs/issues/4899#issuecomment-1688588756).
{: .prompt-info }

## Summary

Migrating Git repositories is simple. However, if the repository contains LFS artifacts, you need to make sure to run the `git lfs fetch` and `git lfs push` commands to migrate them along with the repository. If you don't, your Git LFS files will be missing.
Expand Down
9 changes: 6 additions & 3 deletions _posts/2023-09-07-migrate-to-git-lfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ This post will show you how to migrate large blobs in Git to Git LFS.

If you have a file in the Git history is larger than 100mb, you can migrate it to Git LFS. This will allow you to store the file in Git LFS and keep the file in your Git repository.

> Following these instructions will rewrite Git history (new commit hashes)! Make sure to have a backup of the repository before proceeding.
> Following these instructions will **rewrite Git history** (new commit hashes)! Make sure to have a COMPLETE backup of the repository before proceeding (`git clone --mirror <url>`)
{: .prompt-danger }

Instructions:
> For those using **commit signing**: I have noticed that since the `git lfs migrate import` rewrites history, the commits that it recreates aren't signed.
{: .prompt-warning }

An example script to migrate `.exe`{: .filepath} and `.iso`{: .filepath} files to Git LFS:

```bash
cd ~/Repos/my-git-repo-with-large-files
Expand All @@ -52,7 +55,7 @@ git lfs ls-files # list LFS files
git push --all --force # force push all branches to remote
```

This will migrate all files with the extensions `.exe`{: .filepath} and `.iso`{: .filepath} to Git LFS. The `--everything` option will run the migration in all local and remote Git refs (branches, tags). Additionally, this will also create a `.gitattributes`{: .filepath} file that will tell Git to store all files with the extensions `.exe`{: .filepath} and `.iso`{: .filepath} in Git LFS.
This will migrate all files with the extensions `.exe`{: .filepath} and `.iso`{: .filepath} to Git LFS. The `--everything` option will run the migration in all local and remote Git refs (branches, tags). Additionally, this will also create and commit a `.gitattributes`{: .filepath} file that will tell Git to store all files with the extensions `.exe`{: .filepath} and `.iso`{: .filepath} in Git LFS.

The nice thing about the `--everything` option is that it also works for files that have been committed to history and subsequently deleted, so you don't have to use any additional tools to rewrite history.

Expand Down

0 comments on commit eb330dc

Please sign in to comment.