You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native添加*.hprof到.gitignore无效,GitHub推送报错

为什么添加*.hprof到.gitignore后仍无法忽略大文件?

执行git push origin master时,收到约10条类似错误:remote: error: File android/java_pid60072.hprof is 564.94 MB; this exceeds GitHub's file size limit of 100.00 MB。将*.hprof添加到.gitignore文件并提交后,仍出现该类错误。.gitignore相关片段如下:

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof

问题原因

.gitignore仅对未被Git追踪的文件生效。如果这些.hprof文件之前已经被Git记录(比如不小心提交过),后续添加的忽略规则不会对已追踪的文件产生作用。

解决步骤

  1. 从Git追踪列表中移除.hprof文件(保留本地文件不删除):
    单个文件操作:
    git rm --cached android/java_pid60072.hprof
    
    批量操作所有.hprof文件:
    git rm --cached '*.hprof'
    
  2. 提交移除追踪的操作:
    git commit -m "停止追踪.hprof文件"
    
  3. 再次执行推送:
    git push origin master
    

额外注意

  • 确保.gitignore文件本身已经提交到仓库,否则新克隆的仓库不会自动应用这个忽略规则。
  • 如果这些.hprof文件之前已经推送到远程仓库,上述操作只能阻止后续提交,但远程历史中仍存在大文件。若要彻底清除远程历史中的大文件,可使用git filter-repo工具修改提交历史(此操作会改变仓库历史,需团队成员同步更新本地仓库)。

内容的提问来源于stack exchange,提问作者gkeenley

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 09:42:45