Sekhar
Sekhar

Reputation: 55

Removing file from .git directory from previous commit

I have added charges.txt file of 64 MB size in git repository and did commit ( let git gave me commit hash id x ).
Following above commit, I have also did around 20 more commits to git repository with different changes in each commit.

Now I Found that I have added wrong charges.txt file into git repository. I have removed it using git rebase interactively to my previous commit id x but I have noticed that the files are removed from my working directory but it's not removed it from .git directory as the size of .git folder is almost same before and after my git rebase.

Please suggest me the right way to remove the file completely from .git as well to reduce my repository size? Thanks.

Upvotes: 2

Views: 98

Answers (2)

Git.Coach
Git.Coach

Reputation: 3092

Imagine you deleted your file and the commit accidentally. Git still enables you to undo your mistake by keeping your commits for a certain period of time — the default period is 90 days. This is a good thing.

You can edit the expiration period using the following command:

git reflog expire --expire=time

Git periodically runs a garbage collection, cleaning up the repository and optimising it. It is considered bad practice to run garbage collect manually and if you are not entirely sure that you know what you are doing, I would suggest simply leaving it be. The 64mb of space will show up eventually. If you still would like to remove that commit, try the following:

git reflog expire --expire-unreachable=now --all
git gc --prune=now

Upvotes: 2

NaN
NaN

Reputation: 8641

The BFG Repo Cleaner should solve your problem. Use it like:

bfg --delete-files YOUR-FILE-WITH-UNWANTED-DATA

But be carefull and backup your repo first.

Upvotes: 0

Related Questions