目前我有

空的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 filter-branch --index-filter 'git rm -r --cached --ignore-unmatch <file/dir>' HEAD

这将删除该文件历史记录中的所有内容。问题是该文件出现在历史记录中。

这个命令会改变提交的哈希值,这可能是一个真正的问题,特别是在共享存储库上。不应该在不了解后果的情况下进行。

编辑:git项目现在建议用户使用git filter-repo而不是git filter-branch。


使用git filter-repo

WARNING: git-filter-branch has a glut of gotchas generating mangled history
         rewrites.  Hit Ctrl-C before proceeding to abort, then use an
         alternative filtering tool such as 'git filter-repo'
         (https://github.com/newren/git-filter-repo/) instead.  See the
         filter-branch manual page for more details; to squelch this warning,
         set FILTER_BRANCH_SQUELCH_WARNING=1.

安装

[brew|pip3|...] install git-filter-repo

使用

要删除路径前缀为example/path/ To /something的任何文件,可以运行

git filter-repo --path example/path/to/something--invert-paths

要删除任何没有路径前缀example/path/ To /something的文件,可以运行

git filter-repo --path example/path/to/something

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

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"

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

然后我得到了一个错误的第二个文件,我需要删除: 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来修复这个问题

在那之后,推力通过了!


我也遇到了同样的问题,但没有一个答案适合我。我通过以下步骤来解决:

1. 找出哪个提交包含大文件

git log --all -- 'large_file`

底部提交是结果列表中最老的提交。

2. 找到最古老的那个。

git log

假设你有:

commit 3f7dd04a6e6dbdf1fff92df1f6344a06119d5d32

3. 变基

git rebase -i 3f7dd04a6e6dbdf1fff92df1f6344a06119d5d32

小贴士:

列表项 我只是选择删除提交包含大文件。 你可能会在rebase期间遇到冲突,修复它们并使用git rebase—继续继续,直到你完成它。 如果在rebase使用过程中出现任何错误,git rebase—abort来取消它。


为什么GitHub拒绝我的回购,即使我删除了大文件?

Git存储了你项目的完整历史,所以即使你从你的项目中“删除”了一个文件,Git回购仍然在它的历史记录中保留了该文件的副本,如果你试图推到另一个存储库(比如一个托管在GitHub上的存储库),那么Git要求远程回购具有与本地回购相同的历史记录(即它的历史记录中有相同的大文件)。

我怎样才能让GitHub接受我的回购?

您需要在本地清理项目的Git历史记录,从所有历史记录中删除不需要的大文件,然后只使用“已清理”的历史记录。受影响的Git提交id将会改变。

我如何清理大文件从我的Git回购?

从Git历史记录中清除不需要的大文件的最好工具是BFG Repo-Cleaner——它是一个更简单、更快的Git -filter-branch的替代方案,专门用于从Git历史记录中删除不需要的文件。

仔细按照使用说明,核心部分就是这样:

$ java -jar bfg.jar --strip-blobs-bigger-than 100M my-repo.git

任何超过100MB大小的文件(不是最近提交的文件)都将从Git存储库的历史记录中删除。然后你可以使用git gc清除死数据:

$ git gc --prune=now --aggressive

BFG通常比运行git-filter-branch快10-50倍,而且通常更容易使用。

完全披露:我是好心眼巨人回收清理器的作者。


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

本地删除大文件。 提交本地删除。 软重置回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

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


这对我很管用。来自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完全相同。


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

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

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.


所以我遇到了一个特殊的情况:我从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 lfs migrate import --include="fpss.tar.gz"

这应该用新的LFS引用重写您的本地提交

https://github.com/git-lfs/git-lfs/blob/master/docs/man/git-lfs-migrate.1.ronn?utm_source=gitlfs_site&utm_medium=doc_man_migrate_link&utm_campaign=gitlfs#examples


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

下面这句话解决了这里的问题(答案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>


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

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

这是完成了。


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

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

瞧!对我来说很管用。


而不是做复杂的事情,复制你的回购(在你的电脑上)到另一个地方。删除大文件。做几个推拉动作。然后你的一些文件就会被像“<<<<<< HEAD”这样的东西弄得一团糟。只需将备份文件复制到磁盘上的旧文件夹中。再做一次添加、提交、推送!


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

git reset --hard origin/master

然后再推。


当我的iOS项目没有gitignore文件时,我就遇到了这个问题

我想它可能是想把一个巨大的文件推送到github而github可能拒绝了这个巨大的文件或(多个文件)


如果你上传的是你自己的项目,那么只要去目录所在的文件。 删除大文件。 然后点击“view”(窗口文件) 查看->检查隐藏文件夹 然后你就能看到了。”git的文件 删除.git文件 这将删除所有提交历史记录 然后你可以像新的一样推动你的回购…


不知怎的,这对我很管用。我尝试了所有的解决方案,但这个命令节省了我的时间。希望这也能帮助到你。


git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch <file/folder path>' --prune-empty --tag-name-filter cat -- --all

请自行承担风险。我不会为你的行为负责。

在根目录下执行该命令


对我有用的是:

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


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

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>

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


我也有同样的问题。

为了解决这个问题,我取消了提交。然后,我分别重新提交每个文件。


在GitHub上检查你上次提交的id 然后用这个

Git reset——soft <commit_id>

我想是因为工作。谢谢