目前我有

空的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 rm --cached giant_file
    # Stage "giant_file" for removal with "git rm"
    # Leave it on disk with "--cached". if you want to remove it from disk
    # then ignore the "--cached" parameter
git commit --amend -CHEAD
    # Commit the current tree without the giant file using "git commit"
    # Amend the previous commit with your change "--amend" 
    # (simply making a new commit won't work, as you need
    # to remove the file from the unpushed history as well)
    # Use the log/authorship/timestamp of the last commit (the one we are
    # amending) with "-CHEAD", equivalent to --reuse-message=HEAD
git push
    # Push our rewritten, smaller commit with "git push"

其他回答

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

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

在这里查找文档

我在补充第一个答案。

git filter-branch——index-filter 'git rm -r——cached——ignore-unmatch ' HEAD

从原点到主节点会有一些合并冲突。

你的分支和'origin/master'已经分道扬镳, 分别有114和109个不同的提交。 (使用“git pull”将远程分支合并到您的分支中)

请运行这个

Git重置-硬源/主

它将丢弃我所有阶段性和非阶段性的变化,忘记我当前本地分支上的所有内容,并使其与origin/master完全相同。

我认为这是因为您删除的文件可能已经存在于您的提交,以检查这个第一次使用

git log

这将返回你在当前分支中提交的列表,找到你要找的提交的id,

然后使用,

git show <commit_id>

这应该显示包含文件的提交细节

现在要解决你的问题,使用

git reset --soft HEAD~1

这里HEAD~1上的1代表之前的提交,你可以根据你需要的提交使用不同的数字。 如果你需要第二次最后提交,请使用git reset -soft HEAD~2

这将重置你的Head到以前的提交,如果这个提交没有大文件,那么你可以这样做,

git add .

git commit -m <message_for_commit>

git push origin <repo_name>

else

如果你想重置到一个不包含你的文件的特定提交,只需使用

git reset --soft <commit_id>

然后从这里创建一个新的提交,删除文件并推送它

我遇到了类似的问题,并使用上面的步骤删除文件。它工作得很完美。

然后我得到了一个错误的第二个文件,我需要删除: remote: error: File <path/filename> is 109.99 MB;这超过了GitHub的文件大小限制100.00 MB

我尝试了相同的步骤,得到一个错误:“以前的备份已经存在于<path/filename>”

从这个网站上的研究,我使用命令:git filter-branch——force——index-filter "git rm——cached——ignore-unmatch <path/filename>"——prune-empty——tag-name-filter cat -- --all

工作很好,大文件被删除了。

令人难以置信的是,推送仍然失败了,并出现了另一个错误:curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 104 fatal:远端异常挂起

我通过直接修改.git配置文件- postBuffer = 999999999来修复这个问题

在那之后,推力通过了!

有时文件保存在跟踪历史中,请尝试以下步骤:

如果你看到创建模式中列出了大文件,那么执行: git filter-branch——index-filter 'git rm -r——cached——ignore-unmatch filename' HEAD。 你应该看到一堆重写显示在你的控制台,以: Rm 'filename'和 最后一行Ref被重写了。

这是完成了。