1

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.

  1. 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)

  2. 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

  3. 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

torek
  • 448,244
  • 59
  • 642
  • 775
Walt Howard
  • 7,676
  • 1
  • 16
  • 11
  • Does this answer your question? [How to remove/delete a large file from commit history in the Git repository?](https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-the-git-repository) – joanis Jul 06 '22 at 03:20
  • My preferred answer to that question: https://stackoverflow.com/a/61602985/3216427 though I guess it only covers point 1. of your three sub-questions. - Retracting my close vote, it's only a one-third duplicate... – joanis Jul 06 '22 at 03:21

1 Answers1

0
  1. Yes: see, e.g., How to remove/delete a large file from commit history in the Git repository? (as joanis notes in a comment).

  2. Yes. Consider using git replace to make a substitute commit at the history cut-off point, where the substitute commit has no parents, with:

    git replace --graft <commit-hash>
    

    (Note how we list no new parents.) Once the graft is in place, use the deprecated git filter-branch or the fancy new git filter-repo command 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?

  3. 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 clone checks out the branch of your choice, which is the latest commit on that branch—and simply run rm -rf .git (or whatever your local OS's equivalent is) to destroy the repository while leaving the working tree in place. Then run git init to create a new, empty repository, run git add . to add the entire working tree, and run git commit to create the first and only commit (and then rename the branch if desired).

torek
  • 448,244
  • 59
  • 642
  • 775