本文介绍了迁移到Git LFS和跟踪文件时的命令顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对现有的Git存储库使用LFS并跟踪 *.foo 文件,也将文件转换为历史记录.我想我可以做到:

I want to use LFS for an existing Git repository and track *.foo files, converting the files in history too. I guess I can do this:

git lfs track "*.foo"
# changed `.gitattributes` and all `.foo` files
commit -a -m "Started tracking foo files."
git lfs migrate import --everything --include="*.foo"

我应该像在上面一样在导入存储库之前跟踪文件,还是应该在之后进行?有关系吗?

Should I track the files before importing the repository, as I do above, or should I do that afterwards? Does it matter?

推荐答案

在尝试两种方式时,导入存储库似乎会自动打开LFS跟踪,因此无需使用 git lfs track .

In trying it both ways, it appears that importing a repository will turn on LFS tracking automatically, so there is no need to use git lfs track separately.

git lfs migrate import --everything --include="*.foo"

实际上,如果您首先打开跟踪,那么将有一个额外的提交,其中文件类型被添加到 .gitattributes .事实证明, git lfs migration import 实际上将添加具有正确跟踪信息 .gitattributes 作为历史记录中的首次提交.如果您没有 .gitattributes 文件,则会在过去的 中添加一个文件.

In fact if you turn on tracking first, then you will have an extra commit where the file types are added to .gitattributes. It turns out that git lfs migrate import will actually add a .gitattributes with the correct tracking information as the first commit in the history. If you don't have a .gitattributes file, one will be added in the past.

类似地,如果您没有 .gitattributes (例如,您从Subversion存储库转换了Git存储库),那么如果您首先添加自己的 .gitattributes 到存储库,并在执行 git lfs track 之前提交它,这将导致历史记录中的 .gitattributes 版本,而不是 启用LFS跟踪.如果您确实决定手动添加 .gitattributes ,则应在提交文件之前执行 git lfs track…,以便在其所有提交中都启用跟踪出现.

Similarly if you don't have a .gitattributes (let's say you converted the Git repository from a Subversion repository, for example), then if you first add your own .gitattributes to the repository and commit it before doing git lfs track, this will result in a version of .gitattributes in the history that does not have LFS tracking turned on. If you do decide to add .gitattributes manually, you should perform git lfs track… before committing the file so that it will have tracking turned on in all the commits in which it appears.

所以最好的方法似乎是:

So the best approach seems to be:

  1. 在执行其他任何操作之前,先执行 git lfs迁移….
  2. 使用其他文件类型更新Git添加的 .gitattributes 文件(如果您还没有 .gitattributes 文件).
  1. Perform git lfs migrate… before you do anything else.
  2. Update the .gitattributes file that Git added with extra file types (if you didn't have a .gitattributes file already).

总而言之, git lfs migration import…似乎包含了 git lfs track…功能;似乎没有必要在调用之前或之后单独调用后者.

In summary, git lfs migrate import … seems to include git lfs track … functionality; there seems no need to call the latter separately, either before or after.

这篇关于迁移到Git LFS和跟踪文件时的命令顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-18 23:44