I try to remove unnecessary files from git repository. That files were initially added and now they are in several branches. What I want is simply stop tracking changes in that files, I don't care what changes should stay there, but I need that files to stay on file system.
I tried following
git filter-branch --index-filter "git rm --cached --ignore-unmatch file_to_remove" HEAD
but that removed file from file system what is unwanted.
The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.
git rm will not remove a file from just your working directory. (There is no option to remove a file only from the working tree and yet keep it in the index; use /bin/rm if you want to do that.)
Just:
git rm --cached file [file ...]
Of course you'll need to make sure the offending files are added to your .gitignore
so they don't get recommitted straight away
If you want to keep the file in the repository, you can use: git update-index --assume-unchanged <fileName>
This keeps the current version of the file in the index, but you can change it all you want and git will ignore those changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With