My .git directory is overly large and displeasing me. I have, in the past, added and committed some directories that were full of large binary files. I've subsequently removed them from the latest master, but they are still stored in the history. I will never need them. My primary intent is to reduce the size of the .git directory, with as few side effects as possible.
Can I purge particular directories from the entire repo history, of course potentially causing possible dependency earthquakes (not in this case as these files have no dependents but for future reference)
Can I completely remove all history prior to a particular commit. I have no reason to keep the entire history of this project from day one, and if I did, I could just put it in a fork that I never sync with the main repo
A subset of 2, can I purge the entire repo except for the most recent commit?
What happens if another developer fetch/merges a repo which has been butchered in the above ways?
I know of manual ways to do all of the above but I am lazy and want an easy, git way to do the above with as few commands as possible.
Thanks
Yes: see, e.g., How to remove/delete a large file from commit history in the Git repository? (as joanis notes in a comment).
Yes. Consider using
git replaceto make a substitute commit at the history cut-off point, where the substitute commit has no parents, with:(Note how we list no new parents.) Once the graft is in place, use the deprecated
git filter-branchor the fancy newgit filter-repocommand to "cement the graft into place", as it were. The "empty filter" represented by using no filters at all suffices here. See, e.g., the filter-branch related answers to How to remove/delete a large file from commit history in the Git repository?Yes: this one is particularly easy to do since you can just clone the original repository, check out the desired commit—this may not require any work since
git clonechecks out the branch of your choice, which is the latest commit on that branch—and simply runrm -rf .git(or whatever your local OS's equivalent is) to destroy the repository while leaving the working tree in place. Then rungit initto create a new, empty repository, rungit add .to add the entire working tree, and rungit committo create the first and only commit (and then rename the branch if desired).