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?
-
By added, do you mean: staged (`git add`), commited (`git commit`), or pushed to the remote repository? – bereal Sep 12 '15 at 09:04
-
Yes, exactly. I have pushed them on the repository. – user706838 Sep 12 '15 at 09:08
-
Does anyone else use that repository? Has anything else been added or changed within the same commit? – bereal Sep 12 '15 at 09:13
2 Answers
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

- 2,602
- 2
- 19
- 37
-
-
-
This filters the branch history and removes everything matching `img`. Or do you mean wipe the history in its entirety? I cant think of a reason you would want to do that – hammus Sep 12 '15 at 09:15
-
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".