0

I have a file that for some reason got installed in my project qt-linux-opensource-5.0.2-x86-offline.run. This file is super big so i removed it in git with:

git rm qt-linux-opensource-5.0.2-x86-offline.run

The problem is when i push the file still is trying to be pushed... how do I completely remove this file. I already deleted the file from my computer (didn't want it in that directory) and for extra protection I put it in my git ignore file. I need to update the app but this file is making it impossible thanks to it's 300mb+ size. Thanks to everyone who can help.

cmannett85
  • 21,725
  • 8
  • 76
  • 119
Jakxna360
  • 857
  • 2
  • 9
  • 31

1 Answers1

1

You've already committed the file. Therefore, it's in your history, and git rm won't remove the file from it.

Luckily, you didn't push your commits yet, which enables you to use git filter-branch. The Git Pro book contains a section on this command, and filter-branch's documentation got the right example:

git filter-branch --index-filter \ 
 'git rm --cached --ignore-unmatch qt-linux-opensource-5.0.2-x86-offline.run' \
  origin/master..HEAD

However, make sure that you understand filter-branch before you use it. The book doesn't call it the "Nuclear option" just for fun.

(Also, consider adding *.run to your .gitignore)

Zeta
  • 103,620
  • 13
  • 194
  • 236
  • I ran the filter branch command but the file still tries to push – Jakxna360 Aug 25 '15 at 19:47
  • That's strange. That `filter-branch` command should remove the file from any commit between `origin/master` and `HEAD`. Did you try `git rebase -i origin/master` and removing/editing the commit by hand? – Zeta Aug 25 '15 at 19:50
  • Is their a way to remove by file and not commit? (I don't commit often and add alot of things at once) – Jakxna360 Aug 25 '15 at 19:52
  • Also I don't use branches so everything is on master – Jakxna360 Aug 25 '15 at 20:10
  • I tried the rebase thing and i found the commit from last push but it was automatically added back in (last commit was during a merge) – Jakxna360 Aug 25 '15 at 20:14
  • Wait. Was that a merge from `origin/master`? If that's the case, use `filter-branch ... HEAD` (without `origin/master`). However, it seems like the file was is already upstream from a previous commit. – Zeta Aug 25 '15 at 20:19
  • I figured it out! I re-read the blog post and figured it out! I did: git filter-branch --index-filter \ 'git rm --cached --ignore-unmatch qt-linux-opensource-5.0.2-x86-offline.run' \HEAD. thanks man : ) – Jakxna360 Aug 25 '15 at 22:07
  • @Jakxna360: Which is what I meant by my last comment :D. Your commit was older than `origin/master`, therefore, it wasn't in `origin/master..HEAD`. Glad that I could help. – Zeta Aug 26 '15 at 05:26