Git repository size problem

Asked

Viewed 768 times

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 a git 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?

2 answers

5


Probably what you want is to rewrite the history of your repository, which can be problematic if you don’t know what you’re doing (I don’t know :P). this is done with filter-branch. An example:

git filter-branch --tree-filter 'rm -rf path/file' HEAD

You may need adaptations as needed, so read the documentation.

It is also possible to delete a commit and make a rebase but I think it would be more complicated.

  • This should only be done in the clone, or I can do this also directly in the remote repository?

  • 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.

  • 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.

  • 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.

4

You can make a Cherry-pick and remove or undo a patch.

Here has a good explanation about the Cherry-pick and here has an answered question that closely resembles your problem.

I suggest very calm at this time not to remove anything more than necessary.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.