gpt4 book ai didi

git rm - 致命的 : pathspec did not match any files

转载 作者:IT王子 更新时间:2023-10-29 00:41:07 55 4
gpt4 key购买 nike

我无意中将 9000 多张照片添加到我的项目文件夹中。并 promise 了他们。然后从磁盘中删除它们。坚定的。

现在我尝试将更改推送到 git 服务器。但是它花费的时间太长并且试图发送 12 Gb 的数据。

我检查了磁盘上的文件大小,发现 .git 文件夹确实占用了 12 Gb。

如何从那里删除照片?我尝试了 git rm,但失败了:

❯ git rm public/photos
fatal: pathspec 'public/photos' did not match any files

因为我已经从磁盘中删除了它们,但它们仍在 .git 文件夹中。

我尝试将 public/photos 添加到 .gitignore:

public/photos/
*.zip

但是没有结果。当然,当我的项目中没有那么多垃圾照片时,我可以硬重置头。但从那时起,我 promise 了很多次,并对代码进行了很多更改。

最佳答案

在你的情况下,使用 git filter-branch而不是 git rm

git rm 将删除文件,因为它们将不再被 git 跟踪,但不会删除与这些图像对应的旧提交对象,因此您仍然会被卡住推送对应于 12GB 图像的早期提交。

另一方面,git filter-branch 也可以从所有以前的提交中删除这些文件,因此无需推送任何文件。

  1. 使用命令

    git filter-branch --force --index-filter \
    'git rm -r --cached --ignore-unmatch public/photos' \
    --prune-empty --tag-name-filter cat -- --all
  2. 过滤分支完成后,确认没有意外文件丢失。

  3. 现在添加一个.gitignore 规则

    echo public/photos >> .gitignore
    git add .gitignore && git commit -m "ignore rule for photos"
  4. 现在做一个推送

    git push -f origin branch

检查 this , thisthis寻求进一步帮助。为了安全起见,我建议您在继续执行这些说明之前在您的系统上创建该存储库的备份副本。

至于您的原始错误消息,它的发生是因为您已经使用 git rm 取消跟踪它们,因此 git 提示因为它无法删除它未跟踪的文件。阅读more about this here .

关于git rm - 致命的 : pathspec did not match any files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25458306/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com