Git-lfs: Simple steps to uninstall Git LFS from your repository

Created on 25 May 2018  Â·  8Comments  Â·  Source: git-lfs/git-lfs

it's time to settle this topic once and for all, because answers raised in previous issues about this have proven insufficiently formulated, or are simply outdated with deprecated commands (#316, #641, #910)

i was delighted when git lfs was so easy to install and get started with — but it starts to feel frustrating when git lfs is difficult and confusing to break up with — and boy am i confused

so let's make this easy together — and remember — its not you, it's me
ok ok.. i'm seeing someone else.. it's github pages! (github pages doesn't support lfs)

  1. git lfs uninstall
    this removes hooks and smudge/clean filter configuration
    and this is only the beginning, mua-ha-ha

  2. how can we reindex/re-commit lfs'd files to restore them???
    in this comment @andyneff says:

    you can probably remove the entries from .gitattributes and trigger the git index that every lfs file is different, and then add and commit those files. This is the same procedure in how you change the auto newlines in a git repo. I'll have to test this some, but this might get you in the right direction. The only caviate is you don't want to reset the .gitattributes files first.

    good thing i read just now that this must be done before the .gitattributes step

    but how the heck do we do this? (sure don't want to accidentally change all my newlines, hah)

    is there a way that git lfs can do this for me? after all, it was the one who created this mess to begin with.. ok, ok, i know that line never works in any relationship ;)

    edit: ok, there's some talk in this issue about a methodology

    • git lfs ls-files — view lfs files
    • for each file, use globs if you can:

      • git rm --cached myfile.psd — "remove" the lfs file

      • git add myfile.psd — add the "normal" file

    • git commit -m "restore files from lfs"

    let me know if that makes sense

  3. remove lfs .gitattribute entries
    this will apparently prevent lfs from resurrecting itself

  4. how do we remove remaining files, seen via git lfs ls-files???
    i'm guessing we git lfs untrack them one-at-a-time
    edit: nope, untrack doesn't remove them... hmm... what does it do?
    maybe once i figure out step 2, this'll be done
    edit: yep, step 2 knocks this one out

  5. what do we tell our fellow contributors to do???
    i'm guessing they just need to git lfs uninstall?
    do they also need to git lfs untrack stored files or anything like that?

also, i have no interest in rewriting git history here, that's silly... i just want to move forward with my collaborators once this is taken care of

oh, and obviously, i need some help with the points ending in lots of question marks — once we work through this, i'd like to edit this post into a nice clean list of steps that people can follow — then maybe let's formalize this into some documentation

thanks fellas

Most helpful comment

Thanx, that helped me a lot while I was migrating from BitBucket to AWS CodeCommit. Some helpful hints:

  • commit & push everything
  • remove hooks
    git lfs uninstall
  • remove lfs stuff from .gitattributes
  • list lfs files using
    git lfs ls-files | sed -r 's/^.{13}//' > files.txt
  • run git rm --cached for each file
    while read line; do git rm --cached "$line"; done < files.txt
  • run git add for each file
    while read line; do git add "$line"; done < files.txt
  • commit everything
    git add .gitattributes
    git commit -m "unlfs"
    git push origin
  • check that no lfs files left
    git lfs ls-files
  • remove junk
    rm -rf .git/lfs
  • you're all done
    (but unlinked junk is within BitBucket Git LFS storage still)

All 8 comments

Hi @chase-moskal, thanks for opening this. I agree with the steps you outlined above, and left a few specific thoughts below. In one sense, I'm glad that we have this issue open in order to point people in the right direction should they want to uninstall Git LFS, but in another sense I think that this 5 (6?) step process is too complicated, and should be handled by Git LFS.

Another confusing aspect of this is that git lfs uninstall can be misleading in that it leads users to think that it is "uninstalling" Git LFS from your _repository_, when it is really uninstall Git LFS from your _system_. I think that the ultimate solution to this is a git lfs migrate export command.

As you noted, this does not rewrite history, so checking out previous revisions of your repository under Git LFS will check out pointers, not large objects.

Here are some specific thoughts:

3. remove lfs .gitattribute entries
this will apparently prevent lfs from resurrecting itself

This could occur before step (2) and instead of step(1), which would leave Git LFS installed on your system (in the case that you might interact with a repository that is using it in the future) but would make step (2) do what you expect. Even though Git LFS is configured in $HOME/.gitconfig, your repository doesn't have a .gitattributes telling Git to invoke Git LFS when you re-run git add, so your files are added as expected.

Another caveat of this case is that you must have a local cache of all Git LFS objects for this to work, which you can accomplish by git lfs pull --all.

5.
_what do we tell our fellow contributors to do???_
i'm guessing they just need to git lfs uninstall?
do they also need to git lfs untrack stored files or anything like that?

They should simply pull and checkout the new state of the world, their repository will work as-expected without Git LFS installed.

Thanx, that helped me a lot while I was migrating from BitBucket to AWS CodeCommit. Some helpful hints:

  • commit & push everything
  • remove hooks
    git lfs uninstall
  • remove lfs stuff from .gitattributes
  • list lfs files using
    git lfs ls-files | sed -r 's/^.{13}//' > files.txt
  • run git rm --cached for each file
    while read line; do git rm --cached "$line"; done < files.txt
  • run git add for each file
    while read line; do git add "$line"; done < files.txt
  • commit everything
    git add .gitattributes
    git commit -m "unlfs"
    git push origin
  • check that no lfs files left
    git lfs ls-files
  • remove junk
    rm -rf .git/lfs
  • you're all done
    (but unlinked junk is within BitBucket Git LFS storage still)

As of Git 2.16, the gnarly piece of this process—re-staging the files that were previously in LFS so their contents are in Git again—can be handled entirely using git add --renormalize .. See my Stack Overflow answer here for more details.

can be handled entirely using git add --renormalize .

To clarify, this does _not_ affect earlier revisions of history: if you "remove" Git LFS from your repository and check out a historical revision of your repository, you will not see the large files, and instead only see the pointer representation.

git lfs migrate export _can_ do this, and more information on that is available via man git-lfs-migrate.

LPT: do not remove .git/lfs before you push, or you'll be stuck with lfs failing to push

I summarised everything mentioned above into a gist, please check it out, maybe it helps others in the future like it helped me. Thanks everyone! https://gist.github.com/everttrollip/198ed9a09bba45d2663ccac99e662201

Especially thanks for your script, it saved ton of my times. @fedor57
After do all your steps, I've get rid of LFS in my current repository and current remote,
But because I need to push my repository to new remote (gitlab), then when I run push with git push new-remote --all, it throw error, Can you give a look on it?

longnx@DESKTOP-D46DU6R MINGW64 /d/git/working/edp-ibs-jidou (master)
$ git push gitlab
Enumerating objects: 444, done.
Counting objects: 100% (444/444), done.
Delta compression using up to 4 threads
Compressing objects: 100% (245/245), done.
Writing objects: 100% (444/444), 19.27 MiB | 4.65 MiB/s, done.
Total 444 (delta 190), reused 377 (delta 182), pack-reused 0
remote: Resolving deltas: 100% (190/190), done.
remote: GitLab: LFS objects are missing. Ensure LFS is properly set up or try a manual "git lfs push --all".
To https://gitlab.com/dps-ss/edp-ibs-jidou.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.com/dps-ss/edp-ibs-jidou.git'

easiest way to do it that worked for me :
first commit & push everything
then

git lfs uninstall

then manually remove lfs stuff from .gitattributes
git lfs untrack '<pattern>' (in my case, all files "*.*") git add --renormalize . git commit -m 'Restore file contents that were previously in LFS'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kaixin-bai picture kaixin-bai  Â·  3Comments

Infotaku picture Infotaku  Â·  4Comments

m1h4 picture m1h4  Â·  4Comments

andronocean picture andronocean  Â·  3Comments

pauljohn32 picture pauljohn32  Â·  3Comments