Method to delete commits for reducing repository size

六月ゝ 毕业季﹏ 提交于 2020-07-31 03:46:47

问题


I am using a git repository to deliver .jar files to a client. If I don't delete the old commits, the repository size gets bigger and eventually, Bitbucket disables any new commits. This is how I have been delivering the files:

git reset --hard HEAD~
git push -f origin some-branch
git commit -m "Some message"
git push origin some-branch

Basically, the last commit always contains only the .jar files, I delete it, force push to delete the commit from the remote branch, commit and push the new jars. I have recently switched to this, only to notice it has no effect on repository size (it keeps growing):

git reset --hard HEAD~
git commit -m "Some message"
git push -f origin some-branch

I thought this should have been equal to the previous method. It is not. Why?


回答1:


When you use git push -f the last commit is no longer referenced, but is not deleted. Eventually git will garbage collect orphaned data to save some space.

If you use Bitbucket Cloud, you can contact Support to run a git gc to free some space.

Bitbucket documentation provide advices to reduce repository size : https://confluence.atlassian.com/bitbucket/reduce-repository-size-321848262.html




回答2:


A better answer imho is: don't use a git repo to deliver build artefacts.

Bitbucket and other git services are not file hosting services. Git is designed for tracking changes to source code, so using it to distribute large binary files is not going to end well.

There are many other options available for sharing large binary files, e.g. Google Drive.



来源:https://stackoverflow.com/questions/56423615/method-to-delete-commits-for-reducing-repository-size

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!