问题
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
回答1:
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"
来源:https://stackoverflow.com/questions/59210453/remove-git-lfs-link-to-file-and-add-it-to-git-directly