目前我有
空的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中列出时,文件如何仍然在以太中?
我也遇到了同样的问题,但没有一个答案适合我。我通过以下步骤来解决:
1. 找出哪个提交包含大文件
git log --all -- 'large_file`
底部提交是结果列表中最老的提交。
2. 找到最古老的那个。
git log
假设你有:
commit 3f7dd04a6e6dbdf1fff92df1f6344a06119d5d32
3. 变基
git rebase -i 3f7dd04a6e6dbdf1fff92df1f6344a06119d5d32
小贴士:
列表项
我只是选择删除提交包含大文件。
你可能会在rebase期间遇到冲突,修复它们并使用git rebase—继续继续,直到你完成它。
如果在rebase使用过程中出现任何错误,git rebase—abort来取消它。
你可以使用
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
为什么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倍,而且通常更容易使用。
完全披露:我是好心眼巨人回收清理器的作者。
我尝试了以上所有的方法,但没有一个对我有效。
然后我想出了自己的解决办法。
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.