How to delete files permanently from your local and remote git repositories
BY Anoop John
7 years ago
1 comments comment

If you frequently have to set up git version control system for existing projects then you would very likely run into the problem of having to remove files, which should not have been in git, from git after they were added. Running a git rm will only delete the file from the head and the file would still remain in the repository. This may be alright for small files but this could be troublesome for large files as these would unnecessarily bloat the git repository. But don't worry git being a 'swiss army knife' of version control systems there is a solution to delete files permanently from both your local and remote git repositories.

Do note that this is not a newbie solution and you have to do your bit of reading up on these commands and their implications before you actually run this on a production repository. Also note that you have to have RW+ permissions on the repository to do non-fast-forward pushes

CD to your local working folder and run the following command

git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch FOLDERNAME" -- --all

replace FOLDERNAME with the file or folder you wish to remove from the given git repository.

Once this is done run the following commands to clean up the local repository

rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

Now push all the changes to the remote repository

git push --all --force

This would clean up the remote repository.

Now you will have to recreate the .git folders of all the working copies of the repository. This would include cloned repositories by other developers or the cloned repositories at the live and dev sites. You can do this by cloning the repository afresh into a temporary folder and the move the .git folder from the newly cloned repository to the local repository after deleting the existing .git folder from in there. Do remember to checkout the same branch as is already checked out in the local repository in the temporary repository before you move the .git folder to the local repository.

Remember to make a backup copy of the latest repository and the latest local files before you do any of these things so that you can fall back to a working repository if you run into issues.

Do this if you are confident of your git capabilities or else call up the experts :-). Let us know and we will be happy to offer our offshore Drupal development services to help you maintain your server and your repositories.



on 04th April 2007 / by webmaster
Linux is the epitome of the FLOSS model. Technical Solution Linux installation Dewey J. Corl (not verified) access_time 31 Jul 2021 - 15:05 Linux is not ready for the general public! (I am a Ubuntu user). For proof, 1. try to simply print labels on a Dymo label printer. It takes a LOT of work to get to the ease of label printing already available in Windows and Mac. 2. try syncing a modern Palm based PDA. Yes, jpilot and others will sync the main data, but pictures and midi files do not get transferred without a lot of extra setup. These are examples of applications that are not ready for the general public. Since an operating system only supports applications, Linux is not ready to be a common desktop for the general public. While we are waiting for the applications to catch up, keep up the good work!! Anoop John (not verified) access_time 31 Jul 2021 - 15:05 Dewey Yes you may be right. But these are not applications that a common man would use. A common man would use one of these applications - Internet browser, Chat Client, Email Client, Document Writer, Presentation Creator, Spreadsheet Editor, Movie Viewer, Music Player, CD/DVD Writer. Both examples you cited are more specific applications that only a small percentage of the whole population uses. It will take time before those hardware vendors identify the need from their perspective to address the Linux community. Krishnadas (not verified) access_time 31 Jul 2021 - 15:05 Dear Mr Anoop, Thank you very much for the free installation of LINUX done in my PC. I am getting immersed in the LINUX and seeing the versatility. To my surprise, I am able to read one of my old backup CD(wherein lot of my valuable file exist) done in DIRECT CD wizard (a custom cd writing software of Easy Cd creator in WIN98) which could not be read in XP. Installation of old version of easycd creator/direct cd program was not possible in XP. I thought that possible i lost all data. Very pleasant start! Srikanth N. S. (not verified) access_time 31 Jul 2021 - 15:05 Hi Anoop, My friend is thrilled with Ubuntu. One of his grouses with windows was that after OS installation, everything else is to be installed separately which is a real headache. WHereas if u install Linux, everything is installed as a package and he is thrilled to bits! Let linux installation spread in Trivandrum and your service in this direction is highly appreciated. Kepp up the good work Regards. PDA Freak (not verified) access_time 31 Jul 2021 - 15:05 Is it possible to install linux on a packardbell notebook ?

Bruce Edge (not verified)
access_time 31 Jul 2021 - 19:40

Should you not also use "--tag-name-filter cat " as well?

Using the above command, I get may warnings like:
WARNING: You said to rewrite tagged commits, but not the corresponding tag.
WARNING: Perhaps use '--tag-name-filter cat' to rewrite the tag.