Remove Git lfs link to file and add it to git directly

女生的网名这么多〃 提交于 2020-01-25 04:21:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!