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

部署Spring Boot到Heroku时执行git add .报错求助

部署Spring Boot到Heroku时git add .报错的解决方法

错误信息翻译

warning: in the working copy of 'New Project – Google Cloud console_files/m=b(2)', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'New Project – Google Cloud console_files/m=b(3)', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'New Project – Google Cloud console_files/m=core,pm_welcome_home', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'New Project – Google Cloud console_files/m=core,pm_welcome_home(1)', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'New Project – Google Cloud console_files/m=pm_freetrial_organization_credits', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'New Project – Google Cloud console_files/m=pm_freetrial_signup_dialog', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'New Project – Google Cloud console_files/m=sy13,pm_doc_url_service', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'New Project – Google Cloud console_files/m=sy15,sy1i,sy1m,sy27,sy2g,pm_freetrial_verify', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'New Project – Google Cloud console_files/m=sy17,pm_title_service', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'New Project – Google Cloud console_files/m=sy1n,pm_title_service', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'New Project – Google Cloud console_files/m=sy1z,pm_free_trial_popup', LF will be replaced by CRLF the next time Git touches it
error: open("New Project – Google Cloud console_files/m=sy2,sy4,sy8,sy9,sy3,sy5,sy6,sy7,syl,syf,syj,syk,syn,syy,pm_shortcut_hints_service,syi,sy1f,sy24,sy2d,sy14,sys,sy19,sy2b,syb,syc,syx,sy18,s"): Filename too long
error: unable to index file 'New Project – Google Cloud console_files/m=sy2,sy4,sy8,sy9,sy3,sy5,sy6,sy7,syl,syf,syj,syk,syn,syy,pm_shortcut_hints_service,syi,sy1f,sy24,sy2d,sy14,sys,sy19,sy2b,syb,syc,syx,sy18,s'
fatal: adding files failed

翻译后:

警告:在'New Project – Google Cloud console_files/m=b(2)'的工作副本中,下次Git处理该文件时LF将被替换为CRLF
警告:在'New Project – Google Cloud console_files/m=b(3)'的工作副本中,下次Git处理该文件时LF将被替换为CRLF
警告:在'New Project – Google Cloud console_files/m=core,pm_welcome_home'的工作副本中,下次Git处理该文件时LF将被替换为CRLF
警告:在'New Project – Google Cloud console_files/m=core,pm_welcome_home(1)'的工作副本中,下次Git处理该文件时LF将被替换为CRLF
警告:在'New Project – Google Cloud console_files/m=pm_freetrial_organization_credits'的工作副本中,下次Git处理该文件时LF将被替换为CRLF
警告:在'New Project – Google Cloud console_files/m=pm_freetrial_signup_dialog'的工作副本中,下次Git处理该文件时LF将被替换为CRLF
警告:在'New Project – Google Cloud console_files/m=sy13,pm_doc_url_service'的工作副本中,下次Git处理该文件时LF将被替换为CRLF
警告:在'New Project – Google Cloud console_files/m=sy15,sy1i,sy1m,sy27,sy2g,pm_freetrial_verify'的工作副本中,下次Git处理该文件时LF将被替换为CRLF
警告:在'New Project – Google Cloud console_files/m=sy17,pm_title_service'的工作副本中,下次Git处理该文件时LF将被替换为CRLF
警告:在'New Project – Google Cloud console_files/m=sy1n,pm_title_service'的工作副本中,下次Git处理该文件时LF将被替换为CRLF
警告:在'New Project – Google Cloud console_files/m=sy1z,pm_free_trial_popup'的工作副本中,下次Git处理该文件时LF将被替换为CRLF
错误:打开文件"New Project – Google Cloud console_files/m=sy2,sy4,sy8,sy9,sy3,sy5,sy6,sy7,syl,syf,syj,syk,syn,syy,pm_shortcut_hints_service,syi,sy1f,sy24,sy2d,sy14,sys,sy19,sy2b,syb,syc,syx,sy18,s"失败:文件名过长
错误:无法索引文件'New Project – Google Cloud console_files/m=sy2,sy4,sy8,sy9,sy3,sy5,sy6,sy7,syl,syf,syj,syk,syn,syy,pm_shortcut_hints_service,syi,sy1f,sy24,sy2d,sy14,sys,sy19,sy2b,syb,syc,syx,sy18,s'
致命错误:添加文件失败

解决方案

1. 处理文件名过长的致命错误

  • 直接删除无关文件:从路径能看出,New Project – Google Cloud console_files是谷歌云控制台生成的缓存文件,和你的Spring Boot项目完全无关。直接删除整个文件夹,之后重新执行git add .即可。
  • 开启Git长路径支持(可选):如果确实需要保留长文件名的文件,在终端执行以下命令:
    git config --global core.longpaths true
    
    执行完成后重新尝试git add .

2. 处理换行符转换警告

  • 配置自动换行符处理:在项目根目录创建.gitattributes文件,添加以下内容:
    * text=auto
    
    这样Git会根据操作系统自动处理换行符,避免出现转换警告。
  • 关闭自动转换(不推荐):如果不需要自动转换,执行以下命令:
    git config --global core.autocrlf false
    
    但此方法可能导致跨平台协作时出现换行符不一致的问题,谨慎使用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 15:27:48