Archive

For April, 2017

How to remove permanently an object in GIT

No Comments

To remove permanantly an object in a remote GIT repository, simply perform these steps. Prior executing them, go to the GIT project folder. This is the one having the .git folder.

git filter-branch -f --index-filter "git rm -rf --cached \
     --ignore-unmatch OBJECT-TO-DELETE" -- --all
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
git push --all --force

Replace OBJECT-TO-DELETE with the object to delete. For example, if you want to delete a complete folder called distributions located in the tools folder, replace OBJECT-TO-DELETE by tools/distributions

The local copy of the modified repository cloned else where will have to be re-cloned.

*** Keep a backup your repository before performing these operations ***.

Blue Taste Theme created by Jabox