Git 试图推送未被跟踪的文件

3

我试图将我的项目上传至github,但是遇到了以下错误:

Counting objects: 87, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (78/78), done.
Writing objects: 100% (87/87), 50.25 MiB | 1.14 MiB/s, done.
Total 87 (delta 32), reused 0 (delta 0)
remote: warning: File example-attractor/bin/example-attractor_debug.ilk is 51.19 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: f711bd940689c3c64a38c283877b86f8
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File example-attractor/example-attractor.sdf is 103.62 MB; this exceeds GitHub's file size limit of 100.00 MB
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs

好的,没问题。我将*.sdf*.ilk添加到了我的.gitignore文件中,删除并重新添加了所有文件,并通过git ls-files检查了我的跟踪文件:

.gitignore
example-attractor/README.md
example-attractor/addons.make
example-attractor/example-attractor.sln
example-attractor/example-attractor.vcxproj
example-attractor/example-attractor.vcxproj.filters
example-attractor/icon.rc
example-attractor/src/main.cpp
example-attractor/src/ofApp.cpp
example-attractor/src/ofApp.h

太好了!这些文件已经被移除跟踪。我尝试再次推送到GitHub,但是出现了相同的错误。我运行了git status,但没有任何更改:

On branch master
Your branch is ahead of 'origin/master' by 3 commits.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

我现在很困惑该怎么办!为什么git还在尝试推送未被跟踪的文件?


很遗憾,那里的解决方案都没有解决我的问题 :( - nathan lachenmyer
2个回答

3
最有可能的解释是您在之前的三次提交中提交了该文件。您需要做的是从它们中删除它。通过执行git rebase -i origin/master来完成此操作。这将打开一个编辑器,其中包含所有这些提交。将所有三个提交的“pick”替换为“e”,保存并关闭编辑器。Git现在会在每个提交后暂停,在此时您可以从索引中删除文件,然后执行git commit --amend,最后执行git rebase --continue。然后您应该就没问题了。

1

太好了!文件已经从跟踪列表中移除。

是的,从以后的跟踪列表中移除。但你仍然在本地历史记录中拥有分支master的提交记录。

为什么git仍然试图推送未被跟踪的文件?

当你推送一个分支时,所有尚未在远程分支上的祖先提交记录也会被一并推送到那里。

我现在不知道该怎么办了!

从分支的历史记录中删除不需要的文件,可以使用像David建议的那样master分支上使用git rebase -i origin/master,或者使用git filter-branch。无论哪种情况,在更改任何历史记录之前,请备份您的存储库。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接