首页 > 解决方案 > 文件在未添加的情况下提交到 git repo

问题描述

我有一个在本地创建并建立远程的 git 存储库。我正在尝试将本地存储库推送到远程以进行初始提交。在我的第一次提交中,我收到了这样一条错误消息:

$ git push -u origin master
Counting objects: 65, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (57/57), done.
Writing objects: 100% (65/65), 177.27 MiB | 9.18 MiB/s, done.
Total 65 (delta 6), reused 0 (delta 0)
remote: Resolving deltas: 100% (6/6), done.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 47ec2ee4640f0b04863b99c53fa03943
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File test_data/SoMa_DSM.tif is 399.73 MB; this exceeds GitHub's file size limit of 100.00 MB
To https://github.com/username/VectorAttributes.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/username/VectorAttributes.git'

我将问题文件的文件夹添加到 .gitignore 中,然后按照此问题中的描述清除了我的缓存:Apply gitignore on an existing repository already tracking large number of files 但是,我又遇到了同样的错误。

据我了解,使用git ls-files显示已在本地提交的文件应该是 git 尝试推送到远程的唯一文件。我的问题文件没有出现在那里,但错误仍然存​​在。

为什么 git 仍然试图将该文件添加到远程仓库,即使它不在本地仓库中?

标签: git

解决方案


一些想法:

  • 将 .gitignore 应用于提交的文件

  • 当您的文件夹尚未提交时跳转到您的最后一次提交(所有其他文件也可以反转,所以要小心!)

  • 在文件夹被声明为“已删除”的地方进行提交,然后推送。为此,将您的文件夹移动到存储库之外的目录,从 .gitignore 文件中删除条目,添加提交,推送,将文件夹移回添加到 .gitignore,添加提交并推送。不是 100% 确定它是否有效


推荐阅读