1

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:

  1. Clone the remote repository.
  2. Do git reset --hard HEAD^ to remove the last commit.
  3. 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?

Community
  • 1
  • 1
Daryl McCullough
  • 303
  • 5
  • 20

1 Answers1

1

The size of the remote repo shouldn't matter to the clients who are cloning it: the cloned repo should be small again.

As I mentioned in "Clean up large files on git server", you would need to perform the git gc; git repack -Ad; git prune on the server side, in order to ensure the size of the repo there shrinks.
Depending on the server, that might not be possible. For instance, if that was a GitHub-hosted repo, you would need to contact the GitHub support in order to ensure that cleanup task is performed.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you so much. I have access to the server (not GitHub), so I can run that code. I was a little confused about what commands could be run on a bare repository and what commands couldn't, so I assumed that the cleanup had to be done on a cloned repository and then pushed. – Daryl McCullough Sep 11 '15 at 11:27
  • @DarylMcCullough you can those commands in the bare repo on the server side. – VonC Sep 11 '15 at 12:35