Search code examples
gitatlassian-sourcetree

Too many commits in SourceTree, how to remove them?


I have been using Source Tree for revision management, but also backing up. It ends up with a lot of minor commit that I wouldn't need anymore. How can I remove them?


Solution

  • If you simply want to reduce the number of minor commits in your history, rebase them. This doesn't save disk space because the commits are still retained in hidden history.

    If you are doing this to try to reduce disk space, Atlassian's "How to handle big repositories with Git" suggest the following approaches.

    1. Use shallow cloning to create a repo containing only recent history. (Back up the old repository and put it in a safe place, so that the old history is still available if you need it.)

    2. Use filter-branch to rewrite the history. This changes all of the commit ids, so any existing clones of the repository will need to be re-cloned.

    3. If you have a large binary assets in the repo, then you could use Git LFS or sparse checkout.