How to delete the old git history?

前端 未结 3 1169
你的背包
你的背包 2021-01-30 18:10

I have git repository with many, many (2000+) commits, for example:

                 l-- m -- n   
                /
a -- b -- c -- d -- e -- f -- g -- h -- i --         


        
3条回答
  •  独厮守ぢ
    2021-01-30 18:38

    A possible solution for your problem is provided by git clone using the --shallow-since option. If there is only a small number of commits since f and there is no trouble counting them then you can use the --depth option.

    The second option (--depth) clones only the specified branch. If you need additional branches you can then add the original repo as a remote and use git fetch and to retrieve them.

    When you are pleased with the result, remove the old repository and rename the new one to replace it. If the old repository is remote then re-create it after removal and push from the new repo into it.

    This approach has the advantage of size and speed. The new repo contains only the commits you want and there is no need to run git prune or git gc to remove the old objects (because they are not there).

提交回复
热议问题