列出Git LFS未跟踪的文件 [英] List files not tracked by Git LFS
问题描述
我正在初始化一个带有大量文件的新Git存储库.回购正在使用 Git LFS .我想确保在我第一次提交之前,我已告知LFS跟踪所有应处理的文件.
I'm initializing a new Git repo with a huge pile of files. The repo is using Git LFS. I want to ensure that I've told LFS to track all files that should be handled, before I make my first commit.
我看到提交文件后.
I see that git lfs ls-files
will list all the files that ARE tracked by LFS. However, (a) I want the opposite: all files in the repo that aren't tracked by LFS (and are in .gitignore
), and (b) this command only works after you have committed files.
有人有一些git-fu或Ubuntu-fu来列出回购中所有未被忽略且与Git LFS使用的各种.gitattribute
文件中的跟踪模式不匹配的文件吗?
Does anyone have some git-fu or Ubuntu-fu to list all the files in the repo that aren't ignored and aren't matched by the track patterns in the various .gitattribute
files Git LFS uses?
我最接近的命令是此命令,该命令会列出存储库中超过100kB的文件,然后手动扫描所有文件,并希望我将它们包含在跟踪模式中. >
find . -type f -exec du -Sha -t 100000 {} +
推荐答案
即使问题涉及尚未提交 的文件,但我还是建议一种解决方案,以列出git跟踪的文件,但不列出git-lfs 提交后,您可以通过将git(git ls-files
)跟踪的文件列表与git-lfs(git lfs ls-files | cut -d' ' -f3-
)跟踪的文件列表连接起来,然后仅接收那些在此列表中是唯一的:
Even though the question concerns files that have not been commited, let me suggest a solution to list the files tracked by git but not git-lfs after commit, which you can do by concatenating the list of files tracked by git (git ls-files
) with those tracked by git-lfs (git lfs ls-files | cut -d' ' -f3-
) and then only take the files that are unique in this list:
{ git ls-files && git lfs ls-files | cut -d' ' -f3-; } | sort | uniq -u
如果您发现某个文件已潜入其中,则可以编辑提交(git rm --cached
和git commit --amend
).
After which you could edit your commit (git rm --cached
and git commit --amend
) if you notice a file that has sneaked in...
在预提交阶段,通过观察未跟踪的文件列表并依次使用git lfs track
和git add
进行操作应该非常安全.
At the pre-commit stage, proceeding by watching the untracked files list and successively using git lfs track
and git add
should be quite safe.
这篇关于列出Git LFS未跟踪的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!