2

Our git repository has become bloated with older unused files from previous versions.

I wish to remove the files from future pulls/clones but keep the files in the previous commits so they could be pulled if necessary.

It's not necessary to remove local versions if they are already on a users machine but if a new user pulls the repository then they shouldn't get any of the outdated files.

Is this possible and how would I go about doing this?

Thanks in advance!

MarxWright
  • 307
  • 2
  • 12
  • `git rm --cached ` – Sascha Wolf Feb 04 '15 at 10:49
  • 1
    Have you considered making "new users" do a shallow clone? I mean if it's not essential that they get the entire history regarless.. – Martin G Feb 04 '15 at 11:07
  • 1
    AFAIK this is not possible. To remove those files from future clones you probably have to actually remove these files from the older commits, which rewrites the repo's history. I don't think that is what you want. You could take a look at the [--depth flag](http://stackoverflow.com/a/21217267/1928529) when cloning. – Dennis van der Schagt Feb 04 '15 at 11:08
  • I think adding them to the gitignore file should solve this. –  Feb 04 '15 at 11:55
  • @Martin The shallow clone stuff was very interesting that could be useful, in my case there are backups of a database at different versions of the project in the repo. Would each file still be a valid pull target as it was the last commit for that file? Even if that commit was months ago? – MarxWright Feb 04 '15 at 13:58
  • @purplehuman If all the files are added to the .gitignore would I not have to remove them all again if I wished to put an older commit? – MarxWright Feb 04 '15 at 14:00
  • @MarxWright They would stay where they're in the old commits. But they wouldn't be in the new clones. AFAIK, your gitignore file also updates when you commit. So your old gitignore is there with the old commit. You wouldn't lose anything by trying though. –  Feb 04 '15 at 14:02
  • 1
    @MarxWright Nope, sorry. I just tested it with one of my git repos, and file is still there. I'm sorry, I was wrong. –  Feb 04 '15 at 14:10

1 Answers1

4

You can delete the unused files what you said use git rm, and then the files will disappear from this commit. If you want to find them out, just reset to the old commit, or use the GUI tools.

younghz
  • 66
  • 3