The question of undoing a previous push to a remote repository has been asked several times, but it seems to me that the answers are incomplete. Following the suggestions in Git - Undo pushed commits, I am able to reset a remote repository so that its behavior is as if the last commit never happened. However, it seems that the effects of the undone commit still show up in the size of the git repository.
Here's the hypothetical situation:
A user does git add
, git commit
that puts a huge file, "BigFatFile.bin" into version control. He pushes the changes to the remote repository. Let's suppose that this file is HUGE, maybe 1 GB. We don't want to maintain such files in git. So we try to undo this bad commit as follows:
- Clone the remote repository.
- Do
git reset --hard HEAD^
to remove the last commit. - Do
git push -f
to push changes to the remote repository.
This seems to work, except for the fact that the effects of the push are still visible in the size of the remote repository. Its size has grown by 1 GB.
It is possible on the local copy of the repository to do cleanup steps, using git reflog
and git gc
and git repack
, which reduces the size of the local repository to what it was before the commit of "BigFatFile.bin". But doing a git push
(or git push -f
) doesn't seem to reduce the size of the remote repository.
How can I permanently undo the last pushed commit so that the size of the repository returns to what it was before the push?