Siddhpura Amit
Siddhpura Amit

Reputation: 15128

git trying to push already deleted file from local

I have added my code by

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

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

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

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

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?

Upvotes: 1

Views: 346

Answers (1)

JamesHalsall
JamesHalsall

Reputation: 13505

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^ (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

Upvotes: 4

Related Questions