11

If I push a bad initial commit (or more than one) to a remote repository and want to just clear it / destroy it - can I do it by a command?

It's important to totally remove it from server so it doesn't use disk space.

E.G. Today I pushed a whole Visual Studio project with included dlls, sdfs and so on. Firstly this files are quite big, secondly some of them are modified by VS of other developers and than can't be merged. This made me google a little bit and I found out these files should be ignored. But the first commit already clutters my repository. I want to remove this and free the disk space.

It's possible to remove git repo and add it again via host's website (assembla), but this doesn't sound like solution to me.. Is there a more professional way?


UPDATE:

I tried suggestions from the answer below but it didn't work: 'git push -f' 'git push --force' 'git push origin -f' 'git push origin --force' resulted in:

$ git push --force
Counting objects: 19, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (19/19), 6.85 KiB, done.
Total 19 (delta 3), reused 0 (delta 0)
remote: error: denying non-fast-forward refs/heads/master (you should pull fir
)
To git@git.assembla.com:xxxxx.git
 ! [remote rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@git.assembla.com:xxxxx.git'
Andrzej Gis
  • 13,706
  • 14
  • 86
  • 130

1 Answers1

11

You can force push the "correct" repo with git push -f. Depending on the host, the loose objects will be cleaned up when git gc is ran. update: According to this you can't force the git gc in assembla.

If you want them cleaned up immediately and assembla doesn't allow you to force a git gc, the other option is to delete the repo and push a new one.

In addition, as Ryan stated in the comments, be sure to let everyone know that may have cloned the repo, that you re-wrote history.

Andy
  • 44,610
  • 13
  • 70
  • 69
  • +1, but 1) be sure garbage collection is running regularly, as orphaned objects won't be cleaned up until they become eligible, and 2) make sure everyone knows you're rewriting history. – Ryan Stewart Sep 17 '11 at 00:19
  • 1
    If you can, force a deletion of the remote master branch `git push origin :master`. Some remote repository configurations won't allow for this. – basicxman Sep 17 '11 at 00:21
  • What exactly do you mean by 'delete the repo'? Is there a special command for that, or you just mean to do this via assembla webpage? – Andrzej Gis Sep 17 '11 at 01:04
  • 1
    @gisek Yes, delete it through assembla's interface. – Andy Sep 17 '11 at 02:39
  • Hmm, looks like 'git push -f' doesn't work. Details added to the question. – Andrzej Gis Sep 17 '11 at 13:15
  • May be [this](http://stackoverflow.com/questions/1377845/git-reset-hard-and-a-remote-repository/1377930#1377930) issue. I'd check with assembla. – Andy Sep 17 '11 at 14:20