Skip to content

Commit eb330dc

Browse files
committedAug 13, 2024··
updating LFS posts
1 parent 7e52fde commit eb330dc

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed
 

‎_posts/2023-09-07-migrate-git-lfs-artifacts.md

+17
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ The repository has been migrated, including the LFS artifacts:
5454
![Git LFS file](git-lfs-dark.png){: .shadow }{: .dark }
5555
_File stored in Git LFS file in GitHub_
5656

57+
## Alternative Method
58+
59+
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.
60+
61+
The alternative script to migrate the LFS artifacts to another repository:
62+
63+
```bash
64+
git clone --mirror <source-url> temp
65+
cd temp
66+
for object_id in $(git lfs ls-files --all --long | awk '{print $1}'); do
67+
git lfs push --object-id remote "$object_id"
68+
done
69+
```
70+
71+
> Source for the [script](https://github.com/git-lfs/git-lfs/issues/4899#issuecomment-1688588756).
72+
{: .prompt-info }
73+
5774
## Summary
5875

5976
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.

‎_posts/2023-09-07-migrate-to-git-lfs.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ This post will show you how to migrate large blobs in Git to Git LFS.
4040

4141
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.
4242

43-
> Following these instructions will rewrite Git history (new commit hashes)! Make sure to have a backup of the repository before proceeding.
43+
> 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>`)
4444
{: .prompt-danger }
4545

46-
Instructions:
46+
> 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.
47+
{: .prompt-warning }
48+
49+
An example script to migrate `.exe`{: .filepath} and `.iso`{: .filepath} files to Git LFS:
4750

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

55-
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.
58+
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.
5659

5760
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.
5861

0 commit comments

Comments
 (0)
Please sign in to comment.