目前我有

空的GitHub回购 SSH服务器恢复(main) 当地的回购

SSH服务器回购是最新的回购(生产站点),所以我从那里克隆了一个Git到本地。然后我尝试做一个git推送到GitHub。

一切都很好,但随后它说一些关于文件名。gz对GitHub太大。我不需要这个文件,所以我运行了几个Git命令从Git缓存中删除它,然后推回到SSH服务器。

我没有看到本地的大文件,但它仍然在SSH服务器上,即使git diff返回什么,git推送返回“一切都是最新的”-即使文件在本地回购中不可见,当我尝试推送到GitHub时,我仍然会得到错误

文件fpss.tar.gz是135.17 MB;这超过了GitHub的文件大小限制100mb

我遵循了“修复问题”列在GitHub帮助下的步骤,所以这不应该已经足够了吗?

当它不在本地或在git status/diff/push中列出时,文件如何仍然在以太中?


当前回答

我提出了一个非正统但简单的解决方案:

忘记你最近有问题的本地git存储库,git将你的存储库克隆到一个新的目录中。 Git远程添加上游<你的github代表这里> Git拉上游高手 在这一点上,只需复制您的新文件提交,从旧的可能包括您现在减少的大文件到您的新本地代表。 Git添加。 Git commit -m "你的提交文本在这里" Git push origin master

瞧!对我来说很管用。

其他回答

这对我很管用。来自github的文档 压缩Git提交 Git重置原点/master

git checkout master && git pull;
git merge feature_branch;
git add . --all;
git commit -m "your commit message"

在这里查找文档

我发现压缩比过滤分支更有用。我做了以下事情:

本地删除大文件。 提交本地删除。 软重置回X次提交(对我来说是3):git重置-软头~3。 然后重新提交所有的更改(AKA squash) git commit -m "合并提交的新消息" 推送压缩提交。

特殊情况(来自用户@lituo):如果上述情况不起作用,那么您可能会遇到这种情况。提交1包含大文件,由于大文件错误,提交1的推送失败。提交2删除了git rm——cached [file_name]的大文件,但提交2的推送仍然失败。您可以遵循上面相同的步骤,但不要使用HEAD~3,而是使用HEAD~2。

如果你在寻求帮助之前就已经把你的回购搞得一团糟,我发现这里有一些非常有用的东西。第一类型:

git status

在此之后,您应该会看到类似于

On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

重要的部分是“2次提交”!从这里,继续输入:

git reset HEAD~<HOWEVER MANY COMMITS YOU WERE BEHIND>

所以,对于上面的例子,你可以输入:

git reset HEAD~2

在你输入之后,你的“git状态”应该是:

On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

从那里,您可以删除大文件(假设您还没有这样做),并且您应该能够重新提交所有内容而不会丢失您的工作。

将大文件/文件夹保存在工作文件夹中的解决方案

下面这句话解决了这里的问题(答案1):

git filter-branch——index-filter 'git rm -r——cached——ignore-unmatch <file/dir>' HEAD

如果文件/dir在工作树中,该命令也会删除文件/dir。

如果您希望将文件/文件夹保存在工作树中,我建议执行以下步骤。

错误后运行git重置HEAD^ 将文件/文件夹添加到' '中。gitignore”的文件。 继续像往常一样添加git。它可以捕获其他文件/文件夹,但必须捕获.gitignore文件。接下来是git commit -m"message",最后git push origin <branch_name>

我尝试了以上所有的方法,但没有一个对我有效。

然后我想出了自己的解决办法。

First of all, you need a clean, up-to-date local repo. Delete all the large files. Now create a new folder OUTSIDE of your repo folder and use "Git create repository here" to make it a new Git repository, let's call it new_local_repo. This is it! All above methods said you have to clean the history..., well, I'm sick of that, let's create a new repo which has no history at all! Copy the files from your old, messed up local repo to the new, beautiful repo. Note that the green logo on the folder icon will disappear, this is promising because this is a new repo! Commit to the local branch and then push to remote new branch. Let's call it new_remote_branch. If you don't know how to push from a new local repo, Google it. Congrats! You have pushed your clean, up-to-date code to GitHub. If you don't need the remote master branch anymore, you can make your new_remote_branch as new master branch. If you don't know how to do it, Google it. Last step, it's time to delete the messed up old local repo. In the future you only use the new_local_repo.