2

I have added a folder with images - by mistake - but I realized this just now. Is there any possibility to remove this folder from that day and on without effecting the rest of the files in any way whatsoever?

user706838
  • 5,132
  • 14
  • 54
  • 78

2 Answers2

2

I dont know what you're folder is called but this is what you are looking for (it assumes the folder is called img and only updates the local history)

git filter-branch --tree-filter 'rm -rf img' --prune-empty HEAD
echo img/ >> .gitignore
git add .gitignore
git commit -m 'Removing images folder from git history'
git gc

NOTE: git gc Cleans up the files from the history so you can free up the space they used

hammus
  • 2,602
  • 2
  • 19
  • 37
2

remove this folder from that day and on without effecting the rest of the files in any way whatsoever?

A filter-branch (mentioned in leemo's answer) won't "affect" the file, but will affect the history of the repo.

You will have to do a git push --force in order to publish that correction, which means warn other collaborators to reset their own repo to that new origin/master branch.

And the size won't be smaller until you do a

git gc
git repack -Ad      # kills in-pack garbage
git prune           # kills loose garbage

And it won't get smaller on the remote side unless you have access to that server and perform the same commands on the bare repo: see "Clean up large files on git server".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250