Remove Git lfs link to file and add it to git directly
Asked Answered
E

1

2

I need to remove a Git LFS file pointer, and add the file directly to Git.

I have a filter in .gitattributes to match certain files:

test/**/*.py filter=lfs diff=lfs merge=lfs -text

How can I modify it to exclude 1 file from this pattern?

I tried something like this:

test/**/*.py !test/my_dir/my_file.py filter=lfs diff=lfs merge=lfs -text

but it doesn't seem to work... git says that there is no such file

Errand answered 6/12, 2019 at 9:38 Comment(2)
Is this actually related to Linux from Scratch, or is that an acronym collision with Git Large File Support?Delicatessen
Git Large File SupportErrand
R
6

The .gitattributes file works similarly to the .gitignore file regarding precedence, however the syntax is different. I haven't found this documented anywhere, but I've tested it locally and on GitHub.

After you add the pattern for lfs you can simply add the exception after it so that your .gitattributes file looks like this:

test/**/*.py           filter=lfs diff=lfs merge=lfs -text
test/my_dir/my_file.py filter=    diff=    merge=    text

Then commit your .gitattributes file.

This turns off the lfs filter for that file and won't be tracked by lfs in the future. If the file is already added to the repository, remove it from the repository and re-add it.

$ git rm --cached test/my_dir/my_file.py
$ git add test/my_dir/my_file.py
$ git commit -m "File removed from lfs"
Ridiculous answered 9/12, 2019 at 18:6 Comment(1)
thank you) I decided it differently, but it is more correct, I think ..Errand

© 2022 - 2024 — McMap. All rights reserved.