git试图从本地推送已经删除的文件 [英] git trying to push already deleted file from local

查看:63
本文介绍了git试图从本地推送已经删除的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过

git add .

现在我已经提交了代码,

Now I have committed my code by

got commit -m "Added Filter"

现在,当我尝试通过以下方式推送代码时

Now when I have tried to push code by

git push

我发现有一个名为 java_pid12312.hprof 的文件,其大小超过1 GB,因此我停止了git Control + C

I have found that there is one file named java_pid12312.hprof whose size is more than 1 GB and so I have stopped git by Control + C

现在,我已从查找程序&中删除了该 java_pid12312.hprof 文件.从Mac中的垃圾中删除.

Now I have deleted that java_pid12312.hprof file from finder & from trash in Mac.

现在,我再次尝试推送文件跳动,使该文件无法上传,但是git仍在显示我要上传一个大文件,我检查了我的整个源代码,没有文件大小超过200 kb.

Now I tried again to push file hopping that file will not upload but still git is showing me to upload one large file, I have checked my whole source code there is no file whose size is more than 200 kb.

我认为它可能在缓存中,因此我使用了以下命令将其从缓存中删除

I thought that it might be in cache, so I have used below command to remove it from cache

git rm --cached java_pid12312.hprof

但是它显示了如下错误消息

But it shows me error message like below

fatal: pathspec 'java_pid12312.hprof' did not match any files

这怎么可能?我确定它仍在尝试推送已经删除的 java_pid12312.hprof ,有什么主意吗?

How it is possible? I am sure that it is still trying to push java_pid12312.hprof which I have already deleted, is there any idea?

推荐答案

看起来文件已经被提交,即使您现在已经删除了该文件,该文件仍然存在于您的历史记录中.

Looks like the file has already been committed, and even though you have now removed the file it still exists in your history.

要从历史记录中删除它(前提是尚未将其推送到遥控器),可以执行以下操作:

To remove it from your history, providing the push to the remote has not yet happened, you can do the following:

  1. git reset --soft HEAD ^ (这将通过1次提交后退,但会将文件保留在磁盘上,因此不会丢失任何内容)
  2. rm -f java_pid12312.hprof
  3. git commit -m新提交"
  4. git push
  1. git reset --soft HEAD^ (this will rewind by 1 commit, but preserve your files on disk, so you won't lose anything)
  2. rm -f java_pid12312.hprof
  3. git commit -m "New commit"
  4. git push

这篇关于git试图从本地推送已经删除的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆