0

I had a large git repo with very large history. To reduce the size of the git repo, I removed some large files and replaced the .git file in the repo with a fresh .git file to reduce the size of the repo. The size of the repo is reduced now. However, While cloning the repo in the new instance, the number of the objects to be cloned are not reduced and the clone terminates with the error message:

error: RPC failed; curl 18 transfer closed with outstanding read data 
remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
prajwal_stha
  • 357
  • 3
  • 17
  • 1
    Possible duplicate of [how to delete all commit history in github?](https://stackoverflow.com/questions/13716658/how-to-delete-all-commit-history-in-github) – Durgpal Singh Jan 10 '18 at 11:43

3 Answers3

0

You cant just remove the folder and hope it will work.
If you wish to clean the repo and leave only the last commit you should delete the repo and create it again.

Every time you add file to git, git will start to track changes to this file. So in order to "clean" old objects you have to delete the repo and its history.

# Remove the current objects
rm -rf .git

# Initialize new git repository
git init

# create the .gitignore with your ignored files if needed

# add the desired files to git
git add .

# commit the desired content
git commit -m "Message"

# now push and OVERWRITE!!! the old repsository
git push origin <branch> -f
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • I have followed the steps you outlined above and the history are wiped off. But still, the size of the objects are not reduced. – prajwal_stha Jan 10 '18 at 11:46
  • It means that you have big files in your repo. the files themself are big ones. Try this **DANGER**. The gc will **remove** all old files and will free up sapce. `git gc --aggressive --prune=now` so do it only if you dont care to lose old content – CodeWizard Jan 10 '18 at 12:00
  • Did `git gc --aggressive --prune=now` too. The objects in local repo is reduced but the objects in the repo should be reduced which is not happening. – prajwal_stha Jan 10 '18 at 12:34
0

Simply replacing .git file with another will not work in your case.

  1. rm -rf .git
  2. git init
  3. git add -A fileAndDirectoryName // . If you want to everything available in project directory
  4. git commit -m "Suitable Message"
  5. git push origin branchName -f // Push and Overwrite the existing repo
Shravan40
  • 8,922
  • 6
  • 28
  • 48
0

If you do not have any branches (or if you have but those are redundant and do not care if those get deleted) then simply flatten your repo, check out this.

Else you can shrink the repo, check out this.

In any case I am not sure if history could be the real reason for large size of your repo, it is also possible that some code was cleaned up but there was no re-packaging so all stale things exists, if that is the case then "Reclaim space" section of shrink the repo link should help.

If nothing is helping then go to your ".git" folder of the repo (will be on your disk checkout code) and try to see the files over there, one of the files would be packed-refs which contains information like what all branches etc. are present in your repo, suppose you have removed the branch you if its name still exist in this file then your overall GIT pack size would include that size, so what you can do is delete that particular entry from this file and then execute the step of "Reclaim space" section of shrink the repo link I have provided.

Key is that you will have to debug things at your end because we do not know exact position of your repo.

hagrawal7777
  • 14,103
  • 5
  • 40
  • 70