目前我有

空的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 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>

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

其他回答

你可以使用

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"

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

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

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

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