41

I want to track my frameworks with lfs by a smart way. So this is my setting for git lfs:

*.framework/Versions/A (.gitattributes)
*/*.framework/Versions/A (.gitattributes)
*/{*.framework}/Versions/A (.gitattributes)

But it doesn't work. When I run

"git add ."

there's no files tracked by lfs.

How to fix that. Thank you!

vietstone
  • 8,784
  • 16
  • 52
  • 79

2 Answers2

45

Important: To successfully get Git LFS working, the file may not already be in your Git history.

Mandatory steps:

  1. Install Git LFS via brew (or mac ports.. )

    brew install git-lfs

  2. Initialize LFS inside jour local Git repo. Otherwise your commands will have no effect.

    git lfs install

// Updated pre-push hook. Git LFS initialized.

  1. Do not track the iOS framework directly (eg. "opencv2.framework") because macOS will treat it as a folder. Just track the one large binary file inside the framework.

    git lfs track MyProject/Libraries/opencv2.framework/Versions/A/opencv2

// Tracking MyProject/Libraries/opencv2.framework/Versions/A/opencv2

  1. Add all the files including the new generated ".gitattributes"

    git add .

  2. Commit changes

    git commit -m "added lfs binary"

  3. Now verify the file is properly tracked by LFS

    git lfs ls-files

// 604bd36eb5 * MyProject/Libraries/opencv2.framework/Versions/A/opencv2

  1. Push the commit and see that Git is uploading the large file first

    git push

// Git LFS: (1 of 1 files) 3.54 MB / 87.34 MB

And you are done.

ehrpaulhardt
  • 1,607
  • 12
  • 19
  • 6
    Good answer, but say I have a bunch of .framework, is there a way that I can find all large binary files in whose frameworks, instead of mannally do one-by-one? – Richard Fu Apr 11 '18 at 08:50
  • Run this command in Linux to print out the top 250 largest files in your directory. Do a search for any .framework and add that to your .gitattributes manually with the full path. 'find . -type f -exec ls -alh {} \; | sort -hr -k5 | head -n 250' MyProject/Assets/FacebookSDK/Plugins/iOS/FBSDKShareKit.framework/FBSDKShareKit filter=lfs diff=lfs merge=lfs -text – Gandalf458 Jun 07 '19 at 14:20
  • Interestingly enough, this didn't work for me on a Mac. – BonanzaDriver Jul 01 '20 at 19:18
7

You can follow the next steps to add all frameworks to the git lfs:

brew install git-lfs                                 # install via homebrew
git lfs install                                      # initialize lfs for yor repo
git lfs track ios-app/Frameworks/*.framework/**/*    # track all frameworks in your project
git add --all                                        # stage
git commit -m "Added files to git lfs"               # commit
git lfs ls-files                                     # check that files are tracked

Eventually you should get the next result:

9ee501fdc8 * ios-app/Frameworks/Lottie.framework/Headers/Lottie-Swift.h
8fa3ecc835 * ios-app/Frameworks/Lottie.framework/Info.plist
4a870aa4cc * ios-app/Frameworks/Lottie.framework/Lottie

Take into account that this will not convert any pre-existing files to Git LFS (from other branches or in your prior commit history). To do that, use the git lfs migrate command:

git lfs migrate import --include='ios-app/Frameworks/*.framework/**/*' --everything
sgl0v
  • 1,357
  • 11
  • 13
  • I had the similar issue adding XCFrameworks to LFS and using `*.xcframework/**/*` instead of just `*.xcframework` helped. Thanks! – kelin Sep 01 '22 at 20:10