5
At the company where I work, I was using Git to save a system, where three people use it.
After, by accident, an image folder is sent, make a git pull
has become absurd, since the downloaded data is almost 1.6GB.
Later, we remove this image folder through the file .gitignore
. However, even after this change, the repository continues to be very large.
I have a few questions about that:
How to reduce the size of a Git repository (when an accident like the one above occurs)?
Is there any way to bring one
git pull
or agit fetch
, ignoring some files, such as images and/or videos (through parameters or something like)?Why, even after deleting the large and added files on
.gitignore
, Git still giant? The ignored (previously added) are part of the history?And, if "yes" to the history, there is some way to delete that unwanted files from the history?
This should only be done in the clone, or I can do this also directly in the remote repository?
– Wallace Maxters
Good question. You will have to "replicate" this to all repositories where this file is present. As long as the file exists in some repository, there will be the risk of that file "resurrecting" in the repository when a merge. I don’t know the details because I’ve never had this operation. Changing history is a task that may seem simple but is complicated when there are multiple repositories involved. History modification is only 100% safe if there is no clones, branches, etc., which is rare for anyone using Git. It’s nice to have a clone just to undo if something goes wrong.
– Maniero
These commands must ensure that the file is removed from the remote:
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
git push --all --force
.– Fuad Saud
Note that if the repository with this file has been cloned elsewhere this local copy will not be deleted. Ideally, after upgrading the remote, clone the repository again.
– Fuad Saud