How to reduce the depth of an existing git clone?

前端 未结 4 701
感动是毒
感动是毒 2021-01-03 19:53

I have a clone. I want to reduce the history on it, without cloning from scratch with a reduced depth. Worked example:

$ git clone git@github.com:apache/spa         


        
4条回答
  •  半阙折子戏
    2021-01-03 20:47

    git clone --mirror --depth=5  file://$PWD ../temp
    rm -rf .git/objects
    mv ../temp/{shallow,objects} .git
    rm -rf ../temp
    

    This really isn't cloning "from scratch", as it's purely local work and it creates virtually nothing more than the shallowed-out pack files, probably in the tens of kbytes total. I'd venture you're not going to get more efficient than this, you'll wind up with custom work that uses more space in the form of scripts and test work than this does in the form of a few kb of temporary repo overhead.

提交回复
热议问题