【问题标题】:Git does not detect a deleted file [duplicate]Git没有检测到已删除的文件[重复]
【发布时间】:2016-01-20 09:33:44
【问题描述】:

我正在尝试将我的应用程序代码从 bitbucket 迁移到 github。我更改了文件夹上的遥控器,但是当我尝试推送我的新存储库时出现错误,因为我添加了一个太大的文件。 我删除了文件然后git add . 并提交了更改,但是当我尝试将代码推送到我的存储库时,我仍然遇到与大文件仍然存在相同的错误:

Counting objects: 7302, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5689/5689), done.
Writing objects: 100% (7302/7302), 385.41 MiB | 2.14 MiB/s, done.
Total 7302 (delta 3982), reused 3468 (delta 1527)
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 22d95f5ef2a2bcab974f9ccbe5819675
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File wefootapp.zip is 351.71 MB; this exceeds GitHub's file size limit of 100.00 MB
To git@github.com:davidgeismar/wefootapp.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:davidgeismar/wefootapp.git'

git应该怎么做才能知道文件被删除了?

【问题讨论】:

  • 你用“git rm”删除了文件吗?
  • @DenisFrezzato 你能解释一下这个文件是什么吗?
  • "git rm /path/to/file" 是一个 git 命令,用于从工作树和索引中删除文件。参考:git-scm.com/docs/git-rm
  • 感谢丹尼斯,正如我在下面所说的,我试过了,但我得到了➜ wefootapp git:(master) git rm /Users/davidgeismar/wefootapp/wefootapp.zip fatal: pathspec '/Users/davidgeismar/wefootapp/wefootapp.zip' did not match any files

标签: git github repository


【解决方案1】:

如果你正在跟踪它,你需要告诉 git 它不再存在。

git rm ./local/path/to/file 会将其标记为已删除。

编辑:请参阅this similar question,了解已删除的文件已得到答复。

【讨论】:

  • 我试过了,但我得到了➜ wefootapp git:(master) git rm /Users/davidgeismar/wefootapp/wefootapp.zip fatal: pathspec '/Users/davidgeismar/wefootapp/wefootapp.zip' did not match any files
【解决方案2】:

如果您添加了一个新的提交,并且在引入它的文件之后删除了该文件,并且在提交大文件后没有您希望保留的其他更改,您应该 git reset --hard 添加该文件的提交,删除该文件,然后使用git commit --amend 修改该提交。您可能应该在提交之前将该文件或适当的模式添加到您的.gitignore

如果您在大文件之后引入了您希望保留的其他更改,您可以使用git filter-branch 从历史记录中删除该文件。有一个很好的例子适合你的情况here

只要文件保留在本地历史中的提交中,您的推送就会被拒绝,因此您必须先以某种方式重写您的本地历史。

【讨论】:

    【解决方案3】:

    你不应该在 git 中放置这么大的文件。
    您应该使用此工具来清理您的存储库历史记录:

    https://rtyley.github.io/bfg-repo-cleaner/

    它是完成此类任务的完美工具

    BFG 回购清洁剂

    git-filter-branch 的替代品。

    BFG 是 git-filter-branch 的一种更简单、更快速的替代方案,用于从 Git 存储库历史记录中清除 不良数据

    • 删除疯狂的大文件
    • 删除密码、凭据和其他私人数据

    示例(来自官方网站)

    在所有这些示例中,bfg 是 java -jar bfg.jar 的别名。

    # Delete all files named 'id_rsa' or 'id_dsa' :
    bfg --delete-files id_{dsa,rsa}  my-repo.git
    


    清理存储库后,使用this tool 存储大文件。

    【讨论】:

      猜你喜欢
      • 2023-04-11
      • 2012-03-07
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 2014-02-03
      • 1970-01-01
      • 2021-07-26
      • 2020-08-18
      相关资源
      最近更新 更多