简体   繁体   中英

git bash not realizing that file has been removed from repo on push

I have a repo in which I had a very large file at

assets/vids/bigfile.mp4

At first, I was tracking this folder and it's changes and made several commits while this folder contained this particular large file. Since then I deleted the file manually, then had to go in and remove from being tracked. And since then I have also added the assets/vids/ to my .gitignore since it should not be tracked anyways.

Well, when I try push this project to my github for the first time, during writing objects, it hangs up at around 46% and attempts to load a large file then throws an error message when it realizes the file is over 100mb. It tells me the file is assets/vids/bigfile.mp4 but this folder isn't even being tracked any longer?? The file it is trying to push doesn't even exist in that location any longer. (I don't want it to be)

I used this command to show all files in repo.

git ls-tree --full-tree -r HEAD

The folder I added to .gitignore is not in here so it is a mystery why it is still trying to push this file.

Any ideas on why it's showing up as being in the repo still?

I have tried

git commit -a

and then pushed but it is still giving me the problem.

Because Git keeps track of the full history of your project, any file that has ever been committed becomes a permanent part of your repo. This is by design; imagine that you're browsing your project on Github. You go back in the history to before you stopped tracking that file. Of course it's going to be there, right?

The solution to your problem is the git filter-branch command , which can be used to scrub files from your history. Assuming you want to wipe out any trace of ever having committed the folder, you should be able to use a command like this (may need tweaking, I haven't done this in a while):

git filter-branch --tree-filter 'rm -rf assets/vids' HEAD

As always when rewriting history, be careful!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM