3

I'm getting familiar with git and recently made a mistake: from one computer I added lots of big files (100Mb each, 70GB whole), committed them and pushed to the master. Now, I want to pull on another computer (with a smaller hard drive), and I'm stuck.

I cannot completely pull from the remote repository (due to no space on hard drive) but I also cannot free the local git repository of the bloat.

My question is: how can I revert my repository to the state where it does not need that big amount of local hard disk space? (I will delete the files with next push from another computer).

Korem
  • 11,383
  • 7
  • 55
  • 72
Drey
  • 3,314
  • 2
  • 21
  • 26
  • 2
    Deleting files with a push won't do the job. If you want the files gone and remove the space used by the repo you need to rewrite history. – ThiefMaster Oct 29 '14 at 08:03
  • Do you have shell access on the remote machine? – Chris Martin Oct 29 '14 at 08:06
  • Maybe [BFG](https://rtyley.github.io/bfg-repo-cleaner/) does what you need? (I'm not sure, I just found this - it's referenced from [a github article](https://help.github.com/articles/working-with-large-files/)) – Chris Martin Oct 29 '14 at 08:15
  • @ChrisMartin not directly, that remote machine is at an university. But i can go to an admin if necessary. – Drey Oct 29 '14 at 08:37
  • possible duplicate of [How can I completely remove a file from a git repository?](http://stackoverflow.com/questions/3458685/how-can-i-completely-remove-a-file-from-a-git-repository) – Dettorer Oct 29 '14 at 09:00
  • And a bit lengthier answer : [Remove sensitive data from git](https://help.github.com/articles/remove-sensitive-data/) :) – Dettorer Oct 29 '14 at 09:09
  • @ThiefMaster except if you just want to rewind master to the commit before the addition of the large files (by setting master correctly locally and then use -f when pushing) – Thorbjørn Ravn Andersen Oct 29 '14 at 09:59
  • @ThorbjørnRavnAndersen: That's rewriting history. – ThiefMaster Oct 29 '14 at 10:09

1 Answers1

1

You need to do

git reset

or

git filter-branch

with correct parameters. To rewrite your history.

and then you've to push this with --force to your remote repository. Note that this will make things a bit harder for everyone that uses that repository since they will have to do a rebase or a fresh clone.

git push --force

To remove the commit from your branch. Now the commit will still be present for another 14 days or so on your remote and on the computer that contained that commit. Either you don't care or you run

git gc --prune=now
iveqy
  • 19,951
  • 1
  • 15
  • 20
  • But this doesn't address the problem of how to clone the repo in the first place?. – Chris Martin Oct 29 '14 at 17:11
  • @ChrisMartin Why is that a problem? He had computer 1, computer 2 and computer remote. He has to correct 1 and push that to remote before he can clone to 2. – iveqy Oct 29 '14 at 20:09
  • Thank you very much for the answer. I tried your suggestions - but it did had the strange effect, that i cannot prune the data. Git starts compressing things and tells me that it does not have enough free space (which it doesnt - that the reason i want to prune in the first place :). I guess, i need to delete everything and clone the current repository ... – Drey Oct 30 '14 at 11:06
  • @Drey On the computer with disk space problem you need to delete the repo and clone it again, that's correct. The git gc suggestion is for the first computer, the one that added the huge files. If you're happy with my answer, please mark it as accepted. – iveqy Oct 30 '14 at 18:36