2

I want to delete a git object from the repository without changing any commits. I don't mind if a particular commit that references the blob cannot be checked out correctly. It's more important that the history of the master branch doesn't have to be updated.

There is a myriad answers and tools out there, but all of them change the commits that follow the one that added the blob. Can that be avoided, albeit at the cost of having a "corrupted" commit in the repo?

jcerveny
  • 190
  • 1
  • 6
  • Does this answer your question? [Git - Delete a Blob](https://stackoverflow.com/questions/31855439/git-delete-a-blob) – Saurabh P Bhandari Jan 10 '20 at 08:52
  • 4
    You can't do it. The commit hashes will chage by definition. – w08r Jan 10 '20 at 08:56
  • You could maybe just delete the blob file, but then the repository will be corrupted. – mkrieger1 Jan 10 '20 at 08:57
  • The point is to reduce the size of the repo, I could live with one commit that is corrupted, if that doesn't affect normal work with the repo. – jcerveny Jan 10 '20 at 09:02
  • 1
    Sooner or later it will affect working with the repository. – mkrieger1 Jan 10 '20 at 09:13
  • How? The corrupted commit is deep in the history and it's unlikely anyone will ever want to check it out. – jcerveny Jan 10 '20 at 09:19
  • 1
    For example, `git gc` will be run periodically, it triggers `git repack` which will fail if an object is missing. – mkrieger1 Jan 10 '20 at 09:22
  • 2
    Even if a user might not want to check that commit ever again, a program might. Pushing the repo to a new location for example, or pulling for that matter. – fredrik Jan 10 '20 at 09:23
  • What if the content of the object is deleted. The hash will no longer match, but maybe it will go unnoticed by the maintenance tools? – jcerveny Jan 10 '20 at 09:34
  • 2
    It will not go unnoticed. Git is *designed* to prevent this kind of thing. – mkrieger1 Jan 10 '20 at 09:39
  • What is the problem you are trying to solve by removing a blob? Why do you want to remove it? – mkrieger1 Jan 10 '20 at 09:40
  • To reduce the size of the repo, e.g., when cloning it. Someone committed a large binary file, it got overlooked (the user removed it with git rm) and made its way into master branch history, unfortunately. However, we don't want to rewrite commits in master, as it would affect a lot of people's working copies. – jcerveny Jan 10 '20 at 09:48

0 Answers0