Git LFS 拒绝正确跟踪我的大文件,直到我执行以下操作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35518688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:48:30  来源:igfitidea点击:

Git LFS refused to track my large files properly, until I did the following

gitgithubgit-lfs

提问by Mike Williamson

Problem

问题

I had troubles trying to use git LFS, despite the many suggestions here on SO, on Git and GitHub's documentation, and on some Gists I'd run across.

我在尝试使用git LFS 时遇到了麻烦,尽管这里有很多关于 SO、Git 和 GitHub 的文档以及我遇到的一些 Gist 的建议。

My problem was as follows:

我的问题如下:

After performing the necessary steps:

执行必要的步骤后:

git lfs install
git lfs track "<file of interest>"
git commit

I would still not have any files being tracked. If I performed

我仍然不会跟踪任何文件。如果我执行

git lfs ls-files

it would be blank. If I went ahead & performed the push, the transaction would fail, saying that the files are too large. (As expected, but I was desperate.)

它将是空白的。如果我继续执行推送,事务将失败,说文件太大。(正如预期的那样,但我很绝望。)

回答by Mike Williamson

My (Original Poster) "Solution"

我的(原海报)“解决方案”

I then discovered a few fixes, some of which seem to be bugs, some of which simply were not obvious to me.

然后我发现了一些修复,其中一些似乎是错误,其中一些对我来说根本不明显。

  1. It seems that in order to use lfswith an existing repository, a hack or third party tool such as BFG's converteris needed.

    • I did not want to go that route, so I simply initialized a new repositorylocally, then did the challenge of hooking it back up to the real repo.
    • I created a new directory, then git init, etc.
      • In my case, the remote repository was GitHub. So I did all those proper hookups like git remote add origin [email protected]:<my_id>/<my_repo>.git
  2. Also, while Git's Training Videoclaims that you can simply specify a folder, such as "my_folder/", I could not get this to work. Therefore, I just cleverly used filename extensionsto manage things.

    • For example, git lfs track "my_folder/"would not work for me, but git lfs track "*.zip"did work.
  3. I had no luck getting LFS files to be identified correctly unless I had first updated the .gitattributesfile, and committed and pushed that new file to the remote server.

    • git lfs track "*.zip"
    • git add .gitattributes
    • git commit -m "Updated the attributes"
    • git push
    • git add my_large_file.zip
    • git lfs ls-files
      • And here I would ensure that I saw my_large_file.zipbeing tracked.
    • git commit -m "Now I am adding the large file"
    • git push
  1. 似乎为了lfs现有存储库一起使用,需要 hack 或第三方工具,例如BFG 的转换器

    • 我不想走那条路,所以我只是在本地初始化了一个新的存储库,然后挑战了将它连接回真正的存储库的挑战。
    • 我创建了一个新目录,然后git init,等等。
      • 就我而言,远程存储库是 GitHub。所以我做了所有这些正确的连接,比如git remote add origin [email protected]:<my_id>/<my_repo>.git
  2. 此外,虽然Git 的培训视频声称您可以简单地指定一个文件夹,例如"my_folder/",但我无法让它工作。因此,我只是巧妙地使用文件扩展名来管理事物。

    • 例如,git lfs track "my_folder/"对我不起作用,但git lfs track "*.zip"确实有效。
  3. 除非我先更新了.gitattributes文件,然后提交并将该新文件推送到远程服务器,否则我无法正确识别 LFS 文件。

    • git lfs track "*.zip"
    • git add .gitattributes
    • git commit -m "Updated the attributes"
    • git push
    • git add my_large_file.zip
    • git lfs ls-files
      • 在这里,我将确保我看到my_large_file.zip被跟踪。
    • git commit -m "Now I am adding the large file"
    • git push


It's possible that some of the things work, and I was simply doing them wrong. However, following the witchcraft described above finally got LFS to work, so I thought I'd pass on these details for others, in case someone else had the same problem.

有些事情可能会奏效,而我只是做错了。然而,按照上面描述的巫术终于让 LFS 工作了,所以我想我会把这些细节传递给其他人,以防其他人遇到同样的问题。

回答by Tejaswini

To track all files and sub directories of my_foldervia LFS, you can do:

要跟踪my_foldervia LFS 的所有文件和子目录,您可以执行以下操作:

git lfs track "my_folder/**"

It worked for me.

它对我有用。

Doing the following is not working as of now to track whole my_folderdirectory:

执行以下操作目前无法跟踪整个my_folder目录:

git lfs track "my_folder/" 

is not working

不管用