Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple steps to uninstall Git LFS from your repository #3026

Closed
chase-moskal opened this issue May 25, 2018 · 23 comments
Closed

Simple steps to uninstall Git LFS from your repository #3026

chase-moskal opened this issue May 25, 2018 · 23 comments

Comments

@chase-moskal
Copy link

chase-moskal commented May 25, 2018

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

@ttaylorr
Copy link
Contributor

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.

@fedor57
Copy link

fedor57 commented Jan 4, 2019

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)

@tchebb
Copy link

tchebb commented Jan 9, 2019

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.

@ttaylorr
Copy link
Contributor

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.

shasheene added a commit to shasheene/rescuezilla.github.io that referenced this issue Oct 27, 2019
Replaces Git LFS tracking of images and fonts with regular git tracking using
the approach suggested in [1], because GitHub Pages does not support Git LFS
files (as of writing).

Removing Git LFS entirely was selected over updating URLs to absolute GitHub
paths (as done in [2]) as it's simpler to manage going forward.

[1] git-lfs/git-lfs#3026 (comment) (not
    using the subsequent comment's '--renormalize' due to old Git version).

[2] git-lfs/git-lfs#1342 (comment)
@altschuler
Copy link

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

@everttrollip
Copy link

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

@long-nguyenxuan
Copy link

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'

@kezakool
Copy link

kezakool commented Sep 22, 2020

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' ```

fjuniorr added a commit to fjuniorr/remuneracao-fjuniorr that referenced this issue Dec 2, 2020
@bjennings76
Copy link

bjennings76 commented Jan 17, 2021

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'

FYI, I had this same error when I tried to push a repo to GitLab that at one time had LFS files in its history. I was able to finally fix it by:

  1. Rebasing the entire repo back to when I originally added the .gitattribute file
  2. During the rebase changed the .gitattribute file to remove all references to the LFS file type
  3. Removed/squashed commits that originally changed the LFS files I had swapped out when removing LFS via commits
  4. Continued the rebase
  5. Force-pushed the new commits up to the upstream repo

After that, I was able to push the repo up to GitLab without the LFS objects are missing error.

@gasilva
Copy link

gasilva commented Jan 27, 2021

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' ```

That worked well!!! Thank you.

garrettheath4 added a commit to garrettheath4/zines that referenced this issue Feb 16, 2021
@pratik3098
Copy link

Removing the following files worked for me:
.git/lfs
.git/hooks/pre-push

@hugomarquesdev
Copy link

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' ```

So simple and it worked!! Thanks 😄

@gasilva
Copy link

gasilva commented Jun 1, 2021 via email

@gasilva
Copy link

gasilva commented Jun 1, 2021 via email

@gasilva
Copy link

gasilva commented Jun 1, 2021 via email

@andyneff
Copy link
Contributor

andyneff commented Jun 2, 2021

@gasilva That error message is an error from the "GitHub server", not from you running the "git-lfs client".

That error message says you have a file the violated the GitHub max: countries/historyIC_v2.ipynb

GitHub has a policy, where they no longer allow you to push a commit that contains files larger than 50MB. So the "GitHub server" is telling you "You need git lfs"

EvanDorsky added a commit to EvanDorsky/evandorsky.github.io that referenced this issue Jul 10, 2021
@devBabinski
Copy link

This worked for me:

git lfs uninstall
git lfs uninstall --local
git rm --cached -r .
git push origin main

@longtth
Copy link

longtth commented Jul 20, 2021

This worked for me:

git lfs uninstall
git lfs uninstall --local
git rm --cached -r .
git push origin main

did you tried clone, update, commit, push from another local repo?
I've tried this and it still stuck

@florianseidlschulz
Copy link

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)

This does not work, git lfs ls-files still produces a list of tracked files. Also misses a rm files.txt

yjlolo added a commit to yjlolo/dmelodies_dataset that referenced this issue May 12, 2022
@Aiyualive
Copy link

Aiyualive commented Jul 15, 2022

I just ended up git rm "all the tracked git lfs tracked files".

I dont want to deal with any git rewriting and this allows me to continue my work:)

@PasaOpasen
Copy link

PasaOpasen commented Apr 24, 2023

I used

rm -rf .git/lfs .git/hooks/pre-push .gitattributes

also it's necessary to have write access to .git directory

@tigerhawkvok
Copy link

Created a Python script to do this:

https://gist.github.com/tigerhawkvok/adb7905a2423312f237da1953d6a8eeb

Should work on all platforms (including Windows), and can generate a dry-run script for you to inspect. (Note the dry-run script won't actually edit your .gitattributes or your .git/lfs folder, it'll just show you the new contents of .gitattributes and verify the to-be-removed path)

@roblframpton
Copy link

roblframpton commented Sep 19, 2023

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' ```

Sadly this approach didn't work for me - like @florianseidlschulz, I still get files listed when I run git lfs ls-files.

EDIT: I think I resolved this. I'm not sure how git-lfs detects lfs files, but I used filter-repo to remove the file from the index. Now it no longer shows up in git-lfs.

Also, worth noting that lfs leaves other hooks in pre-merge, pre-commit etc. which also need removing for a full clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests