How to move some files in Git history to LFS with a single command

Thongchai Kolyutsakul
2 min readMar 22, 2022

I’m assuming you already know what Git LFS is and have it set up already.

Today I have updated GoogleCast SDK in my project to 4.7.0 beta which has support for Apple Silicon simulators. I created a pull request and noticed that there is some binary files of size almost 20MB. So I and the team think it’s a good idea to put it in Git LFS.

The problem is, that binary file is already tracked in git months ago. How can I update git’s reference to it throughout the history?

My first idea is I have to git lfs track to update .gitattribute for that file at the right commit, then manually re-add the commits in one big interactive rebase. That’s is… too much.

Fortunately, there is a quicker way using git lfs migrate import . The documentation is here.

Using `git lfs migrate`

Let’s say the file is at **/GoogleCast.framework/GoogleCast. The are 2 variants of it for different architectures.

The GoogleCast framework binary file
  • find the commit BEFORE you added the large file (e.g. 4c3488dafe)
  • run this command

--

--

Thongchai Kolyutsakul
Thongchai Kolyutsakul

Written by Thongchai Kolyutsakul

iOS developer since 2009. Working @Viki in Singapore. I write about iOS development, Swift language, and general software engineers tips.

No responses yet