Git - How to remove files that are listed in the .gitignore but still on the repository

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I have some files in my repository that should be ignored, i added them to the .gitignore but, of course, they are not removed from my repository.

So my question is, is there a magic command or script using filter-branch that can rewrite my history and remove all these files easily? Or simply a command that will create a commit that will remove them ?

Answers

You can remove them from the repository manually:

git rm --cached file1 file2 dir/file3

Or, if you have a lot of files:

git rm --cached `git ls-files -i --exclude-from=.gitignore`

But this doesn t seem to work in Git Bash on Windows. It produces an error message. The following works better:

git ls-files -i --exclude-from=.gitignore | xargs git rm --cached  

Regarding rewriting the whole history without these files, I highly doubt there s an automatic way to do it.
And we all know that rewriting the history is bad, don t we? :)

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/13541615/how-to-remove-files-that-are-listed-in-the-gitignore-but-still-on-the-repositor

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils