惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
Attack and Defense Labs
Attack and Defense Labs
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
F
Full Disclosure
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
V2EX - 技术
V2EX - 技术
B
Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
M
MIT News - Artificial intelligence
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
W
WeLiveSecurity
Stack Overflow Blog
Stack Overflow Blog
TaoSecurity Blog
TaoSecurity Blog
T
Threatpost
小众软件
小众软件
T
The Blog of Author Tim Ferriss
Google Online Security Blog
Google Online Security Blog
MongoDB | Blog
MongoDB | Blog
T
Tenable Blog
P
Privacy International News Feed
S
Security @ Cisco Blogs
H
Heimdal Security Blog
大猫的无限游戏
大猫的无限游戏
B
Blog RSS Feed
H
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Proofpoint News Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
有赞技术团队
有赞技术团队
Application and Cybersecurity Blog
Application and Cybersecurity Blog
O
OpenAI News
Security Latest
Security Latest
S
Securelist
Cyberwarzone
Cyberwarzone
D
Docker
S
Schneier on Security
V
Vulnerabilities – Threatpost
The GitHub Blog
The GitHub Blog
P
Privacy & Cybersecurity Law Blog
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research

Yunfeng's Simple Blog

2025年终总结 lyrichroma-一键将语音转换为视频的Python命令行工具 JiT论文阅读Back to Basics-Let Denoising Generative Models Denoise Lepton AI后续 llm-code-scorer wavlm-large模型onnx和mnn版本的导出与使用 解决Manus Blog自动跳转无法访问的问题 Pytorch转ONNX报错-Cannot insert a Tensor that requires grad as a constant 用MOSS-TTSD生成相声 张小珺明超平访谈观点总结 Qwen VLo 效果实测 美团 NoCode 简单使用体验 AI时代的产品文本化 Comma v0.1 -全开源数据训练的可复现大模型 用gradio部署mcp server repetition_penality的作用与实现 bitnet-b1.58-2b-4t Neovim conceal机制导致markdown语法隐藏的问题 Quotation Armin Ronacher's Reflecting on Life
git lfs pointer 报错解决
Yunfeng Wang · 2025-06-02 · via Yunfeng's Simple Blog

1. 问题说明

在git管理中,有时候会遇到下面的报错:

1
2
Encountered 1 file that should have been a pointer, but wasn't:
/path/to/file

或像下面这样:

1
2
3
Encountered <n> files that should have been pointers, but weren't:
/path/to/file1
/path/to/file2

调查一番后发现,这种报错的核心原因是本应该用Git LFS管理的文件,直接被git来管理了。报错中提到的pointer ,实际上指的就是Git LFS 格式的文件,它不包含完整的数据,而只是一个指向完整数据的指针。

知道这个原因后,解决方法也很简单,而且git lfs v2.2.1 及以后版本提供了git lfs migrate 命令,专门来处理这种情况,也就是将Git管理的文件迁移到用Git LFS来管理,例如,如果已经有一个可以track *.mp4 二进制文件的.gitattributes 配置,使用下面的命令可以将所有mp4文件转换为用Git LFS来管理:

1
git lfs migrate import --include="*.mp4"

执行完这个命令后,还需要用下面的命令清理.git 目录,将缓存的object数据去掉:

1
2
git reflog expire --expire-unreachable=now --all
git gc --prune=now

2. 为什么会出现这种错误

我自己的经验中,最常出现这种情况的原因是,Xcode中添加文件到工程,Xcode自动添加文件到Git管理中,但没有遵循.gitattributes 文件中的规则,将本来应该用Git LFS管理的文件格式直接提交到Git了,所以出现冲突。

另外一种情况是git lfs 配置项被临时禁用,导致添加某些文件的过程中lfs 机制没有生效,下面是这种情况的一个完整复现例子,实际中出现的可能性不大:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash


TEST_DIR="lfs-error-test-$(date +%s)"
echo "创建测试目录: $TEST_DIR"
mkdir -p "$TEST_DIR"
cd "$TEST_DIR"


echo "初始化本地仓库..."
git init
git lfs install


echo "Initial commit" > README.md
git add README.md
git commit -m "Initial commit"


echo "*.bin filter=lfs diff=lfs merge=lfs -text" > .gitattributes
git add .gitattributes
git commit -m "Add .gitattributes"


echo "临时禁用 Git LFS..."
git config --local filter.lfs.process ""
git config --local filter.lfs.required false


echo "创建测试二进制文件..."
dd if=/dev/zero of=test1.bin bs=1M count=1 2>/dev/null
dd if=/dev/zero of=test2.bin bs=1M count=1 2>/dev/null


echo "添加二进制文件..."
git add test1.bin test2.bin
git commit -m "Add binary files without LFS"


echo "重新启用 Git LFS..."
git config --local filter.lfs.process "git-lfs filter-process"
git config --local filter.lfs.required true


echo "创建第二个仓库..."
cd ..
git clone "$TEST_DIR" "${TEST_DIR}_clone"

这个脚本中,git config --local filter.lfs.processgit config --local filter.lfs.required false 就是关掉LFS作用的两条命令。

3. git lfs 的调试命令

在调查问题的过程中,也发现了更多的git lfs的命令,这里也列出来,调试问题的时候时有用的。

git lfs status 会列出当前lfs文件的修改,包括已经git commit提交的,已经git add stage但没git commit提交的,和没有git add处于unstaged的所有lfs 文件。

git lfs pull 会拉取原始的文件,这条命令可以重新拉取git clone时没有拉取的文件。

git lfs ls-files 会列出所有用git LFS 管理的文件,调试很有用。

git lfs fsck 命令会检查用Git LFS管理的文件是否正常,像上面遇到的问题,用这个命令就能很容易测试出来。--objects 选项只检查对应的object对象,而--pointers 只检查对应的pointer文件。

4. 参考资料

除了上面提供的解决方案外,还有一些解决方法,但可能会需要--hard 提交,有危险性,这里就不列出来了 ,具体可以在下面的参考资料中找到。

  1. git-lfs tutoral
  2. https://stackoverflow.com/questions/46704572/error-with-previously-committed-files-which-matches-new-git-lfs-filter
  3. Encountered 1 file(s) that should have been pointers, but weren’t · Issue #1939 · git-lfs/git-lfs