I have a project where I stored video files with Git LFS. Now I ran into some complications with my build server that doesn't yet support Git LFS. As it's an external service, I can't really affect the build process, and thus would want to move the files from under Git LFS back to "regular" Git. I managed to untrack the file types with git lfs untrack '<file-type>'
but git lfs ls-files
still gives a list of the files previously added.
I imagine I could remove the files, push the changes and then manually re-add them, but is this really the recommended way of doing things?
Git LFS stores the binary file content on a custom server or via GitHub, GitLab, or BitBucket's built-in LFS storage. To find the binary content's location, look in your repository's . git/lfs/objects folder.
$ git lfs install Git LFS initialized. You'll only need to run git lfs install once. Once initialized for your system, Git LFS will bootstrap itself automatically when you clone a repository containing Git LFS content.
I have just recently run into this problem where assets were accidentally added to git-lfs on one branch that shouldn't have been. My solution was:
git lfs untrack '<file-type>' git rm --cached '<file-type>' git add '<file-type>' git commit -m "restore '<file-type>' to git from lfs"
The result is a rewrite of the git-lfs oid sha256 pointers with the standard file contents.
(Edit 2019-03): The accepted answer was changed to provide an easy solution for simpler cases. See also the edits in the answer by VonC for alternate solutions in case you have a more complex case on hand.
As of Git 2.16 (released Jan 17th, 2018), you can do this easily with the --renormalize
flag of git add
:
git lfs untrack '<pattern>' git add --renormalize . git commit -m 'Restore file contents that were previously in LFS'
From Git's documentation:
--renormalize: Apply the "clean" process freshly to all tracked files to forcibly add them again to the index. This is useful after changing
core.autocrlf
configuration or thetext
attribute in order to correct files added with wrong CRLF/LF line endings. This option implies-u
.
The key part here is "all tracked files". Normally, filters are only run when a Git operation changes a file in the work tree. Changing the LFS whitelist in .gitattributes
isn't a Git operation, and so the index ends up in an inconsistent state after you run git lfs untrack
. Running git add --renormalize .
tells Git to re-run filters on every file in the repository, which ensures that all files which should be in LFS are—and that all files which shouldn't be aren't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With