7

I had made several local commits to my codebase, and tried to push it to my repo, but there were quite a lot of large files. I just kind of gave up, and continued working, making local commits. I've deleted the large files now, and committed again, but it's still trying to push the original large files. I tried adding a gitignore in after I committed them originally to ignore any file over 50mb, to no avail.

Any ideas?

Gentatsu
  • 173
  • 1
  • 1
  • 4

1 Answers1

12

Read here about filter-branch.

Someone accidentally commits a huge binary file with a thoughtless git add ., and you want to remove it everywhere. Perhaps you accidentally committed a file that contained a password, and you want to make your project open source. filter-branch is the tool you probably want to use to scrub your entire history. To remove a file named passwords.txt from your entire history, you can use the --tree-filter option to filter-branch:

$ git filter-branch --tree-filter 'rm -f passwords.txt' HEAD
Rewrite 6b9b3cf04e7c5686a9cb838c3f36a8cb6a0fc2bd (21/21)
Ref 'refs/heads/master' was rewritten

You can also do an interactive rebase onto your branch at the point where you commited those files, and remove them from that commit. The link above also explains this, but basically:

git rebase -i HEAD~X

will allow you to edit the last X commits.

ladorm
  • 256
  • 2
  • 6
  • I have quite a lot of large files, though, and it seems like it'd take a while like that. – Gentatsu Mar 22 '17 at 12:07
  • I guess you mean with filter branch because of the several files. Cant you use a regex to get to them all? Then maybe the second option (rebasing) its easier cos you can go to that commit and delete the files from the system the same way you deleted them alrerady – ladorm Mar 22 '17 at 12:18
  • Wouldn't it have an effect on my current files, though? Would they not get changed also, or would I have to merge them? – Gentatsu Mar 22 '17 at 16:03
  • If you dont touch your files they won't change. The rebase takes your files back in history to the point of that commit and starts re-applying your commits. It stops on the commit you marked for editing. On that commit you have to remove those files, and then commit with 'git commit --ammend' (its on the link I gave you). This modifies your commit and then you resume the rebase and it starts to apply the rest of your commits – ladorm Mar 22 '17 at 20:01
  • Forgot about this! I did a rebase, and just squashed all my commits, which included the new ignore file, and this worked. – Gentatsu May 08 '18 at 08:39