目前我有

空的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中列出时,文件如何仍然在以太中?


当前回答

对我有用的是:

重命名我的GitHub项目文件夹到其他东西 用正确的文件夹名称重新克隆repo 删除我重命名的repo中的.git文件夹(可能必须打开允许查看Windows中的隐藏文件) 将.git文件夹从正确的文件夹名移动到已重命名的文件夹名 删除重新克隆的repo文件夹,将原repo文件夹重命名为正确的名称 提交您的更改(没有大文件)并推送

其他回答

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

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

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

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

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

这是完成了。

使您的本地回购与远程回购匹配(所有本地更改将丢失):

git reset --hard origin/master

然后再推。

所以我遇到了一个特殊的情况:我从gitlab克隆了一个存储库,其中包含一个大于100 mb的文件,但在git历史的某个时刻被删除了。后来,当我添加了一个新的github私人回购,并试图推到新的回购,我得到了臭名昭著的“文件太大”错误。到此为止,我不再能够访问原始的gitlab回购。然而,我仍然能够在我的机器上的LOCAL存储库上使用bfg-repo-cleaner推送到新的私有github回购:

$ cd ~
$ curl https://repo1.maven.org/maven2/com/madgag/bfg/1.13.0/bfg-1.13.0.jar > bfg.jar
$ cd my-project
$ git gc
$ cd ../
$ java -jar bfg.jar --strip-blobs-bigger-than 100M my-project
$ cd my-project
$ git reflog expire --expire=now --all && git gc --prune=now --aggressive
$ git remote -v # confirm origin is the remote you want to push to
$ git push origin master

如果这个文件是你最近一次提交时添加的,而且你还没有推送到远程存储库,你可以删除这个文件并修改提交。

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"