-1

Accidentaly I pushed a commit including files that should have been ignored (node_modules and bower components directories). As I was using many dependencies, the commit got pretty big and lot of data got uploaded.

I deleted those files in another commit and included a .gitignore file, however every time I clone the app all those big files are downloaded as the history of the project.

Is there any way to get rid of that? A way to definitly remove node_modules and bower components directory from my git repo?

jviotti
  • 17,881
  • 26
  • 89
  • 148
  • Probably a duplicate of http://stackoverflow.com/questions/2116778/reduce-git-repository-size, http://stackoverflow.com/questions/5563564/remove-files-from-git-repo-completely, http://stackoverflow.com/questions/872565/remove-sensitive-files-and-their-commits-from-git-history, or http://stackoverflow.com/questions/9854810/cleaning-up-git-history. – Todd A. Jacobs Jan 10 '13 at 23:17

3 Answers3

1

you can rewrite git history and remove this objects from git. Look on next link https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History

Chance Smith
  • 1,211
  • 1
  • 15
  • 32
iMysak
  • 2,170
  • 1
  • 22
  • 35
  • 3
    This did the trick: **git filter-branch --tree-filter 'rm -f passwords.txt' HEAD**. I have that book in my shelf.. I have to read it definitly :) – jviotti Jan 10 '13 at 23:17
0

I would say

git commit --amend

or

git commit --rebase

But if the file you want to remove has been there for quite some time then :

git filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD
Benjamin Toueg
  • 10,511
  • 7
  • 48
  • 79
0

Even if you perform a git rm, the files will continue in the project history. That way, you will have to download them when you clone the repository. To remove the files forever, you need to change the history.

If the commit that added the files are very recent, you can perform a git resetto a commit before the commit that added the files. But, if the files were added some time ago, you need to use git filter branch. I will show some steps that I use when I want to delete big files from the repository.

git filter-branch --index-filter 'git rm --cached --ignore-unmatch file-or-directory-that-you-want-to-remove-with-complete-path' --all.

Then, you need to perform a git push -f because you changed the project history. This way, when you clone the project again, the files that were removed will not be downloaded anymore.

William Seiti Mizuta
  • 7,669
  • 3
  • 31
  • 23